| Author |
how to use javascript variable in jsp page
|
pravin rasal
Ranch Hand
Joined: Jul 27, 2011
Posts: 63
|
|
Hello,
I have problem that I want to use javascript variable in jsp page. I use one combo box and i want to use combo box indexed value in jsp
How to use that javascript variable in jsp without submitting form.
|
 |
Ashwini Kashyap
Ranch Hand
Joined: Aug 30, 2012
Posts: 62
|
|
Hi,
I will suggest you to make use of jquery rather than making use of javascript.
JQuery is much more advanced than javascript.
Thanks and Regards,
---------------------------------------------------------------------------------------
Ashwini Kashyap | akashyap@infocepts.com | www.infocepts.com
---------------------------------------------------------------------------------------
|
 |
Vishal Shaw
Ranch Hand
Joined: Aug 09, 2012
Posts: 179
|
|
Ashwini Kashyap wrote:Hi,
I will suggest you to make use of jquery rather than making use of javascript.
JQuery is much more advanced than javascript.
Thanks and Regards,
---------------------------------------------------------------------------------------
Ashwini Kashyap | akashyap@infocepts.com | www.infocepts.com
---------------------------------------------------------------------------------------
jQuery is a library of javascript only.
|
Programming is about thinking, NOT coding
|
 |
Ashwini Kashyap
Ranch Hand
Joined: Aug 30, 2012
Posts: 62
|
|
Hi Vishal,
Yes thats true. "JQuery" specifically I mentioned since he might not be aware about the term/power of JQuery.
Thanks and Regards,
---------------------------------------------------------------------------------------
Ashwini Kashyap | akashyap@infocepts.com | www.infocepts.com
---------------------------------------------------------------------------------------
|
 |
pravin rasal
Ranch Hand
Joined: Jul 27, 2011
Posts: 63
|
|
|
thanks Ashwini and vishal for reply ..but my problem is that how can i use javascript/ jquery variable in jsp page..
|
 |
Vishal Shaw
Ranch Hand
Joined: Aug 09, 2012
Posts: 179
|
|
pravin rasal wrote:thanks Ashwini and vishal for reply ..but my problem is that how can i use javascript/ jquery variable in jsp page..
You use javascript variable inside the <script> tag. Look at the given tutorial
|
 |
jatan bhavsar
Ranch Hand
Joined: Jul 23, 2008
Posts: 296
|
|
hi,
if you thinking assigning script variable's value to jsp (server side variable) then it's not possible. you can assing server side variable to script variable. other wise as people said you can use <script> tag to use javascript.
Regards
Jatan
|
 |
Ashwini Kashyap
Ranch Hand
Joined: Aug 30, 2012
Posts: 62
|
|
Suppose you have following combo box:
<select id="fruit" name="fruit">
<option value="">Select Fruit </option>
<option value="apple">Apple</option>
<option value="orange">Orange</option>
</select>
You can get selected option like:
var fruit_selected = $('#fruit').val(); // Using JQuery
$("#fruitSelected").val(fruit_selected); // Assign value of selected option into text field
Also, you can do like assign this fruit to a textfield in jsp like:
<input type="hidden" id="fruitSelected" />
For more refer to site : JQuery
Regards,
Ashwini Kashyap
|
 |
Abhishk Singh
Ranch Hand
Joined: Aug 19, 2010
Posts: 32
|
|
jQuery can increase the page size.
For an alternative you can save the value in some page element using javascript.
For eg. document.getElementById("elementId").innerHTML or document.getElementById("elementId").value=<Desired value>
At later point, in some other javascript method when you want to use this value, just fetch this value using javascript.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56531
|
|
abhishek singhania wrote:jQuery can increase the page size.
This is usually not a problem, and using a CDN can ensure that the code is already cached. This is not a reason to avoid jQuery.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56531
|
|
pravin rasal, please read this article ti understand how JSP works and why you cannot use a JavaScript value in the JSP that generates the page.
This is also covered in the JspFaq. Be sure to check the FAQ first, before posting.
|
 |
 |
|
|
subject: how to use javascript variable in jsp page
|
|
|