• 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:

Using input value from JavaScript prompt in JSP

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 148
Hibernate Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
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

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
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

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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic