View Full Version : on click event in javascript

09-10-2011, 10:28 AM
Hai all,

iam trying to use java script code in my jsp page.

i used a onclick event.while clicking on the button that wil goes to the javascript function(deleteRecord(name,subject)).
this deleterecord() wil post the url request.

my code is like this

function deleteRecord(name,subject){

document.write("name received is:"+name);
var url="http://localhost/myproject/DeleteRecord?";
var url1= "name="+name;
var url2="subject="+subject;
var URL=url+url1+url2;

my onclickevent code is'
<td width="20%" height="25" align="left" valign="middle"><input type="submit" name="delete" value="Delete" style="background-color:#ff0000;font-weight:bold;color:#ffffff;" onclick="deleteRecord(<%=rs.getString("name")%>,<%=rs.getString("subject")%>);" /></td>

wil iam running my jsp page internet explorer is giving in variable subject (error:'divi' is invalid).divi is the value of the parameter name which iam passing to the function .
and mozilla firefox my script is not working
there is some syntax issues as wel as browser issues...and with url syntax
can any one help me...

Old Pedant
09-10-2011, 09:22 PM
You don't show where you assign your <form> to your variable f

Did you forget that? Or did you just not show it?

In any case, the line


should be

f.action = URL;

I really think, though, that there is a simpler way to do this.

Old Pedant
09-10-2011, 09:24 PM
Oh, and you forgot the & between the first and second parameters in the URL.

var URL=url+url1+"&" + url2;