File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes get the  textbox values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "get the  textbox values" Watch "get the  textbox values" New topic

get the textbox values

Sophia Choi
Ranch Hand

Joined: Mar 22, 2002
Posts: 106
I use a for loop to create the textboxs like the following.
<input type="text" name="con_mark_<%=i%>" size="5" maxlength="3">
<input type="text" name="exam_mark_<%=i%>" size="5" maxlength="3">
But I meet a problem to retrieve their values in JavaScript.

var frm = document.forms[0];
var num_students = frm.num_students.value;

for(var i=0; i < num_students ; i++){
var con_mark = "con_mark_"+i;
var exam_mark = "exam_mark_"+i;
var attendance = "attendance_"+i;
alert(frm.con_mark_+i.value); --> null
How can I get their values ?
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

Try using ev_al() such as:

The String evaluates to the correct alert function, then gets executed by the JS engine.
(UBB doesn't like the word ev_al, so remove the underscore)
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
this is wrong
try this
I agree. Here's the link:
subject: get the textbox values
It's not a secret anymore!