*
The moose likes JSP and the fly likes in jsp i want touse java script  variable value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "in jsp i want touse java script  variable value " Watch "in jsp i want touse java script  variable value " New topic
Author

in jsp i want touse java script variable value

kapil bhate
Greenhorn

Joined: Mar 04, 2004
Posts: 15
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
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Mar 04, 2004
Posts: 15
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.
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
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:


- Varun
kapil bhate
Greenhorn

Joined: Mar 04, 2004
Posts: 15
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

Joined: May 30, 2002
Posts: 1400
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

Joined: Mar 04, 2004
Posts: 15
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

Joined: Mar 04, 2004
Posts: 15
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

Joined: May 30, 2002
Posts: 1400
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

Joined: Mar 04, 2004
Posts: 15
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

Joined: Mar 04, 2004
Posts: 15
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
Winston Smith
Ranch Hand

Joined: Jun 06, 2003
Posts: 136
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.


for (int i = today; i < endOfTime; i++) { code(); }
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61224
    
  66

"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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
kapil bhate
Greenhorn

Joined: Mar 04, 2004
Posts: 15
thanks varun so what is solution for it?how i amm using that script value in sql query?or never?
pl. reply
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
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.


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61224
    
  66

"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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: in jsp i want touse java script variable value