Same function different results...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • danarz@

    Same function different results...

    If you invoke the "check_link " function using the "Go" link than
    everything works as I expect.
    If invoking it using the Submit button than the text field value shows
    the new value ("Executed Link") for a split second and than reverts
    back to the default value.

    Why?


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head><meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1">
    <title>Untitl ed Document</title>

    <script type="text/javascript" language="javas cript">
    function check_link()
    { var new_link=docume nt.getElementBy Id('fName').val ue;
    var newwin = window.open(new _link, "temp_win") ;
    document.getEle mentById('fName ').value='Execu ted Link';
    }
    </script>

    </head><body>
    <form name="form1" method="post" action="">
    <input name="fName" type="text" id="fName" value="http://google.net">
    <a href="javascrip t:check_link()" >Go</a><br>
    <input name="Submit" type="submit" onClick="check_ link();"
    value="Submit">
    </form>
    </body>
    </html>

  • Martin Honnen

    #2
    Re: Same function different results...



    danarz@ wrote:

    [color=blue]
    > If invoking it using the Submit button than the text field value shows
    > the new value ("Executed Link") for a split second and than reverts
    > back to the default value.[/color]

    As the submit button submits the form the action URL is being requested
    by the browser, with action="" the browser submits to the page itself.
    If you do not want to submit the form data then don't use a submit button.

    --

    Martin Honnen

    Comment

    • Lee

      #3
      Re: Same function different results...

      danarz@ said:[color=blue]
      >
      >If you invoke the "check_link " function using the "Go" link than
      >everything works as I expect.
      >If invoking it using the Submit button than the text field value shows
      >the new value ("Executed Link") for a split second and than reverts
      >back to the default value.
      >
      >Why?[/color]

      Because the submit button submits the form.

      With no action specified, submitting the form causes the page to reload.
      Don't use the onClick event handler of a submit button.
      Don't use a submit button at all, if you don't really want to submit a form.

      Comment

      Working...