• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Javascript to Java

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

How to pass the JavaScript variable to the java, below is the code I am executing.

Currently I am getting an Javascript error Object expected.

Can any one please suggest regarding this.

function disp_confirm(profileid)
{
var name=confirm("Are you sure you want to delete this profile?")
if (name==true)
{
<%
ph.setCurrentProfileID((int)Integer.parseInt(profileid));
%>
}
}
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the Java code is part of an applet, then you may be able use LiveConnect.

If the Java code runs on the server, then it is not possible to mix it with JavaScript (which runs on the client).
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ravi,

The code you have written results in the deletion of the profile even before coming to the client side because you have <%
ph.setCurrentProfileID((int)Integer.parseInt(profileid));
%>
, which will be executed at the server side.

To send any value from HTML to server, you have to send one more request to the server, using form submission, XMLHttpRequest, IFrames, etc.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use a hidden input to pass the value:



In your java code, you can access the profileid by using:



[ July 18, 2006: Message edited by: jaikiran pai ]

[ July 18, 2006: Message edited by: jaikiran pai ]
[ July 18, 2006: Message edited by: jaikiran pai ]
 
Ravi Rao
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi jaikiran,

With the below code I am able to delete the profileid and reloading the same Jsp.

Thanks you very much for you are help.


<html>
<head>
<script type="text/javascript">
function disp_confirm(profileid)
{
var name=confirm("Are you sure you want to delete this profile?")
if (name==true){
document.getElementById("h1").value=profileid
document.myForm.submit();
}
}
</script></head>
<body><form id="myForm">
<input type="hidden" id="h1" />
</form></body>
</html>

--------------------------------------------------------------------------------



In your java code, you can access the profileid by using:


code:
--------------------------------------------------------------------------------

request.getParameter("h1");
 
Sheriff
Posts: 67746
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
Ravi Rao, you have a fundamental misunderstanding about how JSP works. You cannot do what you are trying to accomplish in that manner.

Please read this article for information on why Javascript and Java cannot interact in the way that you are attempting.
 
Get out of my mind! Look! A tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic