Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    on click event in javascript

    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);
    f.method="post";
    var url="http://localhost/myproject/DeleteRecord?";
    var url1= "name="+name;
    var url2="subject="+subject;
    var URL=url+url1+url2;
    f.action(URL);
    f.submit();
    }


    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...
    Regards,
    Divya

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,496 Times in 4,460 Posts
    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
    Code:
    f.action(URL);
    should be
    Code:
    f.action = URL;
    I really think, though, that there is a simpler way to do this.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,496 Times in 4,460 Posts
    Oh, and you forgot the & between the first and second parameters in the URL.

    var URL=url+url1+"&" + url2;
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •