changing ONCLICK

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stefan Finzel

    changing ONCLICK

    Hi

    what's the right way to add ONCLICK to a form button using javascript?

    <HTML>...
    <INPUT ID="RESET" NAME="RESET" TYPE="RESET" VALUE=" Reset ">No onclick
    is used here


    <SCRIPT TYPE="text/javascript">...
    form.RESET.clic k = "javascript:res et_action();"
    ....
    </SCRIPT>

    TIA

    Stefan
  • Randy Webb

    #2
    Re: changing ONCLICK

    Stefan Finzel said the following on 10/2/2005 2:20 PM:
    [color=blue]
    > Hi
    >
    > what's the right way to add ONCLICK to a form button using javascript?
    >
    > <HTML>...
    > <INPUT ID="RESET" NAME="RESET" TYPE="RESET" VALUE=" Reset ">No onclick
    > is used here[/color]

    That is because reset buttons have a default action.
    [color=blue]
    >
    > <SCRIPT TYPE="text/javascript">...
    > form.RESET.clic k = "javascript:res et_action();"
    > ....
    > </SCRIPT>[/color]

    Don't use a reset button if you don't want normal reset actions. Use a
    plain button instead.

    Give your form a name.
    Access the button through the forms collection.
    Give it an onclick (not click) action.

    document.forms['formNAME'].elements['elementNAME'].onclick=reset_ action;

    <form name="formNAME" >
    <input type="button" value=" Reset " name="elementNA ME">

    --
    Randy
    comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly

    Comment

    • BootNic

      #3
      Re: changing ONCLICK

      > "Stefan Finzel" <Stefan.G.R.Fin zel@T-Online.de> wrote:[color=blue]
      > news:dhp8dh$hqe $05$1@news.t-online.com....
      >
      > what's the right way to add ONCLICK to a form button using
      > javascript?
      >
      > <HTML>... <INPUT ID="RESET" NAME="RESET" TYPE="RESET" VALUE=" Reset
      > ">No onclick is used here
      >
      > <SCRIPT TYPE="text/javascript">... form.RESET.clic k =
      > "javascript:res et_action();" ... </SCRIPT>[/color]

      If you want to run some javascript when the form is reset you may
      want to consider using onreset=""

      <form action="javascr ipt:void();" id="myform" name="myform"
      onreset="alert( 'well done grasshopper')">

      Add onreset to form:

      document.forms['myform'].onreset =
      function r(){alert('well done grasshopper')};

      OR add using Id

      document.getEle mentById('myfor m').onreset =
      function r(){alert('well done grasshopper')};

      Add onclick:

      document.forms['myform'].elements['reseta'].onclick =
      function r(){alert('well done grasshopper')};

      OR add using Id

      document.getEle mentById('reset a').onclick =
      function r(){alert('well done grasshopper')};

      <form action="javascr ipt:void();" id="myform" name="myform">
      <input id="reseta" name="reseta" type="reset" value=" Reset ">
      </form>

      --
      BootNic Sunday, October 02, 2005 8:43 PM

      Thirty-five is when you finally get your head together and your body starts falling apart.
      *Caryn Leschen*

      Comment

      • Stefan Finzel

        #4
        Re: changing ONCLICK

        As this should run on older Pocket IE (Win CE 2003 SE) is seems for me
        only the click-Method is available.

        But nethertheless using ONRESET immediatly is working and a better way
        to get it right. So there is even no need to differ between browsers
        here any more.

        Thanks to all!

        Stefan

        Comment

        Working...