Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

how to use javascript variable in jsp page

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
---------------------------------------------------------------------------------------
 
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ashwini Kashyap
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 300
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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



 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 67619
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Bear Bibeault
Sheriff
Posts: 67619
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic