• 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

form field's value from a string

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have the name of the form field in a variable as string.
how can i get its value?

for example:

i.e how to get the value of the textbox with name "age" as 34?

<input type="text" name="age" value="34">

var myTextBox = "age" ;
myTextBox .value =??
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ais,
You would do:
document.nameOfForm.age.value

Note that if you give the text field an id attribute, you can get the element by id rather than navigating through the form.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ais,

There are a number of ways to go about this. If you know at compile time the name of the input whose value you want, you can use the first line below. If you're determining at runtime the name of the input, you can use the second example. It takes advantage of the fact that forms, just like all javascript objects, are really just associative arrays (similar to Maps in Java).


[ April 13, 2007: Message edited by: Scott Escue ]
reply
    Bookmark Topic Watch Topic
  • New Topic