Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

to get value from text box using javascript

 
balaji karth
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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
 
pankaj kapoor
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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;
 
Arvind Sampath
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • 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
 
Niki Nono
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic