Meaningless Drivel is fun!*
The moose likes JSP and the fly likes Using input value from JavaScript prompt in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Using input value from JavaScript prompt in JSP" Watch "Using input value from JavaScript prompt in JSP" New topic
Author

Using input value from JavaScript prompt in JSP

Saurabh Vakil
Greenhorn

Joined: Apr 16, 2012
Posts: 2
Dear Experts,

I am having one JSP page within which I need to show a popup and accept user input. For this I have written JavaScript code within the same JSP to show a Prompt to accept the input from user.
Now the value which the user has entered is within JavaScript's <script>... </script> block.

I want to use this value in the JSP page, but I do not want to forward the request to another JSP. I wish to use the Javascript variable within the same JSP page.

Below is the code I am using:


I am new to JSP. I have searched this forum and found some threads with similar issues, but am not able to get a clear understanding on how exactly to proceed.
Can anyone point me out to the right direction?

Warm regards,
Saurabh
Vijay Tidake
Ranch Hand

Joined: Nov 04, 2008
Posts: 146

Hi,
you can use a hidden variable on the page and once the user entered value you can set the value of this hidden variable on the same jsp page.
eg. document.getElementById('variableid').value = mobNo;

Thanks


The important thing is not to stop questioning.Curiosity has its own reason for existing.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

Saurabh Bv wrote:I wish to use the Javascript variable within the same JSP page.

Impossible. Unless you can invent a time machine. By the time the JavaScript executes, the JSP is long gone.

Please read this article to understand how JSP operates.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

Vijay Tidake wrote:you can use a hidden variable on the page and once the user entered value you can set the value of this hidden variable on the same jsp page.

Nope. Because there is no such thing as a JSP page on the client. The JSP executes on the server to send an HTML page to the browser. Please read the article.
Saurabh Vakil
Greenhorn

Joined: Apr 16, 2012
Posts: 2
Dear Bear,

Thanks for the inputs. The JSP page, within which I am writing my code to accept user input, is a standard component inside SAP Portal.
I cannot show any input field within the same JSP to take user input. Can you suggest what can be the best way to do this?

And I need to use this user input from the same JSP to store its value.

Warm regards,
Saurabh Vakil
Vijay Tidake
Ranch Hand

Joined: Nov 04, 2008
Posts: 146

Hi Bear,
Sorry about the misinterpretation of the question by me as my eyes skipped the part
<%
//This is where I want to use the value which is in the mobNo variable
%>
I thought he would be using the input value on the same page but not inside the jsp tags.

Thanks
 
jQuery in Action, 2nd edition
 
subject: Using input value from JavaScript prompt in JSP