• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

get the textbox values

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
Thanks.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using ev_al() such as:

The String evaluates to the correct alert function, then gets executed by the JS engine.
Dave
(UBB doesn't like the word ev_al, so remove the underscore)
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is wrong
alert(frm.con_mark_+i.value);
try this
alert(frm["con_mark_"+i].value);
reply
    Bookmark Topic Watch Topic
  • New Topic