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 5 of 5
  1. #1
    New Coder
    Join Date
    Sep 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem moving inline JS to a function??

    Hi, just a quick query. I have some inline javascript to submit a form with an onclick event.
    I just recently decided to pull the script into a function and send the relevant URL info as a variable.
    All seemed fine until I re-tested in IE5 - it now will not submit the form, although the code should be the same.
    The function works in IE6, Opera, Safari, Camino and IE5.2 (Mac)
    What has happened with it in IE5?!

    Any thoughts?

    Original inline JS:

    PHP Code:
    onClick="window.document.myform.action='mypge2.asp';
    window.document.myform.method='GET';
    window.document.myform.submit(); return false;" 

    New function to replace inline JS (With alerts):

    PHP Code:
    function nextpage(page) {
    alert(page);
    window.document.myform.action=page;
    window.document.myform.method='GET';
    alert(window.document.myform.method);
    window.document.myform.submit();
    return 
    false;

    Event to access function:

    PHP Code:
    onClick="nextpage('mypge2.asp')" 

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Why return false?
    That might muck things up.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New Coder
    Join Date
    Sep 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the reply nikkiH,
    I just realised that the 'return false' was copied over from the onclick event and should not have been - thanks for pointing that out.
    I have removed this from the function but unfortunately it doesn't seem to sort out the problem...strange, not really sure why this isn't working in IE5. A test page on the same machine with the original inline JS still works.

    ??

    RJW

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,047
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Where is the onclick attached?
    Try this:

    Code:
    onClick="nextpage('mypge2.asp');return false;"
    or put back the return false inside the function and do this:

    Code:
    onClick="return nextpage('mypge2.asp')"
    If still this does not solve your problem, you need to elaborate on what was really happening. Does the page stop from submitting? At what point does the debug alert show?

  • #5
    New Coder
    Join Date
    Sep 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up That's it working now.

    Glenngv,
    Yes, it was the return false not being re-applied to the onclick link, putting it on the onclick for the function call sorted out the problem.
    As posted:
    Code:
    onClick="nextpage('mypge2.asp');return false;"
    Thanks for your help.

    RJW


  •  

    Posting Permissions

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