• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Prasanna Raghavendar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65129
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
document.getElementById('txt').value = whatever;

"txt" is a really poor name to use.

 
Prasanna Raghavendar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34870
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic