This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Assigning a text box value to a variable inside a javascript function (portlet factory) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Assigning a text box value to a variable inside a javascript function (portlet factory)" Watch "Assigning a text box value to a variable inside a javascript function (portlet factory)" New topic
Author

Assigning a text box value to a variable inside a javascript function (portlet factory)

Prasanna Raghavendar
Greenhorn

Joined: Sep 15, 2011
Posts: 19
Hi,

I am working with portlet factory. I have a text box(say, <input type="text" name="txt" id="txt">) inside a form in one page and i submit it to the next page(say "page2")...Inside "page2" when a button is clicked, a function named "assignValues()" will run as a java script.

function assignValues(){
var x = <!-- How should i assign the text box value over here? -->
}

My doubt is, how should i assign the text box value to the var x?

Thanks
Prasanna
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

document.getElementById('txt').value = whatever;

"txt" is a really poor name to use.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Prasanna Raghavendar
Greenhorn

Joined: Sep 15, 2011
Posts: 19
Actually my text boxes are auto generated based on the input value, "NumberOfTextBoxes".
I need to assign the value of each textbox using an array, quest[].

I am doing this part inside a for loop.

for(var i = 0; i<n; i++){
temp = "qid"+(i+1);
alert("temp =" + temp ); <!--I am getting the value of temp(which is the id of each text box in the previous page) correctly here like qid1, qid2, qid3-->
quest[i] = document.getElementById(temp).value; <!--After this line my code stops working-->
alert("quest["+i+"]="+quest[i]);
}

What could possibly be the reason for my code stopping at this point.

PS: I have created an array, "quest" like
var quest = new Array();
at the begining of my javascript.

Thanks
Prasanna
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30123
    
150

What does alert(document.getElementById(temp)) display?

Also, try doing a "view source" to make sure the text field has the same id (not just name) that you are expecting.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Assigning a text box value to a variable inside a javascript function (portlet factory)
 
Similar Threads
Dynamic Form Element
problem with select box
Need to select text from Div section
IE: window.opener is null
Liferay Portlet with JSF Portlet bride-Problem