• 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
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

in jsp i want touse java script variable value

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i write one jsp in that i used one combo box and selecting value from combo which i take in reg_form1.hdnCustType.value form now i want to use this value in jsp
pl.help
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What exactly is your problem?
If you want to use Java Script variable in JSP then you can assign this value to hidden form field and pass with request. So that the value will go with this hidden field, can be retrived with request.getParametr.
- Gajanan C. S.
 
kapil bhate
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by kapil java:
i write one jsp in that i used one combo box and selecting value from combo which i take in reg_form1.hdnCustType.value form now i want to use this value in jsp
pl.help


i am using same page not forwarding request to another page.
 
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by kapil java:

i am gouing to show u code
1>
String sql= " select GNPM_ID, GNPM_DSCRPTN from GN_PRDCT_MSTR where GNPM_ID IN ( SELECT GNCPM_GNPM_ID FROM GN_CTGRY_PRDCT_MSTR where GNCPM_GNCCM_ID="that java script varaible value which is dynamic)";


Where are you executing this SQL statement?
In the same JSP where your javascript variable is present? :roll:
 
kapil bhate
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Varun Khanna:

Where are you executing this SQL statement?
In the same JSP where your javascript variable is present? :roll:


yes in same jsp i amm using that script nariable value!
pl. reply
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by kapil java:
in same jsp one value i have to select from combo ok.then on click i call one function in that function i write one (jsp) sql in that query i want to take value from that combo and depending on that value i want to fetch record which i want to populet.(same page)all dynamically..
pl.reply


- So you are having a SQL query string in the Javascript function.
- And you are picking the value of the combo and appending it in the SQL string.
(something like
var sql ="Select ......." + document.formname.comboname.value + "...");
- Now you are passing the "sql" query value to the server (may be through some hidden variable) and executing it in server .
- Displaying the result back in JSP.
That helped?
P.S. Do remember that the Javascript code is executed at the client side and Java code at the server side.
[ March 04, 2004: Message edited by: Varun Khanna ]
 
kapil bhate
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Varun Khanna:

- So you are having a SQL query string in the Javascript function.
- And you are picking the value of the combo and appending it in the SQL string.
(something like
var sql ="Select ......." + document.formname.comboname.value + "...");
- Now you are passing the "sql" query value to the server (may be through some hidden variable) and executing it in server .
thanks varun so what is solution for it?how i amm using that script value in sql query?
pl. reply
- Displaying the result back in JSP.
That helped?
P.S. Do remember that the Javascript code is executed at the client side and Java code at the server side.
[ March 04, 2004: Message edited by: Varun Khanna ]

 
kapil bhate
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks varun so what is solution for it?how i amm using that script value in sql query?or never?
pl. reply
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by kapil java:
thanks varun so what is solution for it?how i amm using that script value in sql query?or never?
pl. reply


So my last post didn't sounded like a solution to you :roll:
Execute the query at the server (in some servlet or Database object java class maybe depending upon your architectue) and return the result to some 2.jsp and display in the way you want
[ March 04, 2004: Message edited by: Varun Khanna ]
[ March 04, 2004: Message edited by: Varun Khanna ]
 
kapil bhate
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Varun Khanna:

- So you are having a SQL query string in the Javascript function.
- And you are picking the value of the combo and appending it in the SQL string.
(something like
var sql ="Select ......." + document.formname.comboname.value + "...");
- Now you are passing the "sql" query value to the server (may be through some hidden variable) and executing it in server .
thanks varun so what is solution for it?how i amm using that script value in sql query?
pl. reply
- Displaying the result back in JSP.
That helped?
P.S. Do remember that the Javascript code is executed at the client side and Java code at the server side.
[ March 04, 2004: Message edited by: Varun Khanna ]

 
kapil bhate
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in same jsp one value i have to select from combo ok.then on click i call one function in that function i write one (jsp) sql in that query i want to take value from that combo and depending on that value i want to fetch record which i want to populet.(same page)all dynamically..
pl.reply
 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You cannot pass javascript variables to JSP, as the JSP code has already executed (hence the "server-side" aspect) when it arrives at the client machine. The only way you can do this is dump the javascript variable into a hidden FORM field and submit this FORM to another JSP page for processing, where you can retrieve the value, run your query, and return the results to the user.
 
Sheriff
Posts: 67762
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
"kapil java" and "Gajanan C. S.",

You'll find this forum a great place to seek help on JSP pages, and there aren't many rules you'll have to worry about, but one is that proper names are required. Please take a look at the JavaRanch Naming Policy and change your display name to match it.
In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.
Thanks!
bear
JSP Forum Bartender
 
kapil bhate
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks varun so what is solution for it?how i amm using that script value in sql query?or never?
pl. reply
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the best way you can do is, consider the JS variable as a parameter, and send it back to the server as a request parameter, so that the server can receive the parameter and you can use it to fit into the SQL query.
Does this possible?
Nick.
 
Bear Bibeault
Sheriff
Posts: 67762
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
"kapil java",
Please read my post regarding your display name again and change your display name before your next post. This is not a suggestion. Accounts that do not have valid display names are closed.
thanks,
bear
JSP Forum Bartender
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic