• 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

to get value from text box using javascript

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all
i have a jsp page in which i have a textbox.
i like to get the value entered into the textbox and set it to a string variable.

i tried with javascript

eg: String val = document.form1.view.value;
where form1 is the form name;
view is the textbox name;

thank you all,
balaji
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To store value using javascript you have to use

var v = document.form1.view.value;
not
String val = document.form1.view.value;
 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Balaji,

Why do you want to store the value entered in the textbox in a String variable ? If you want to get the value entered in the text at the server side, use request.getParameter("view") (assuming view is the name of your text box). If you need to get the value entered in the text at the client side go as per Pankaj's advice.

Cheers
Arvind
 
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you will have to make one thing clear in your mind first.

javascript runs at client and jsp runs at server. So values of either are not accessible directly.

JSP ultimately converts to html form, so you can put some jsp variable values in the html which can be used bhy javascript.
But for javascript values to be accessible in jsp, you send it as a part of you post.

Then as Arvind said you use request.getParameter("JAVASCRIPT ELEMENT NAME")
to access the value.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic