This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using input value from JavaScript prompt in JSP

 
Saurabh Vakil
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 148
Hibernate Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 148
Hibernate Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic