• Post Reply Bookmark Topic Watch Topic
  • New Topic

Javascript to Java  RSS feed

 
Ravi Rao
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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));
%>
}
}
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • 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).
 
Pavan Keely
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • 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.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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");
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66260
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!