image type button not starting javascript action

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

    image type button not starting javascript action

    This works:
    <input type="button" value="Add to list" onClick="addOpt ion(param1,
    param2);">

    But this doesn't:
    <img src="images/add.gif" onClick="addOpt ion(param1, param2);">

    The error I get using the img tag is, "this.form has no properties". Yet it
    is right beside the input tag that does work with the same OnClick= params

    This doesn't work either:
    <input type="image" src="images/add.gif" value="Add to list"
    onClick="addOpt ion(param1, param2);">

    The error I get with this is that it does the javascript action then Submits
    the form - I do not want it to submit, just do the javascript action.

    What can I do to get a graphic button that will complete the javascript
    action?

    Thanks!


  • Michael A. Vickers

    #2
    Re: image type button not starting javascript action

    Notgiven wrote:
    >This doesn't work either:
    ><input type="image" src="images/add.gif" value="Add to list" onClick="addOpt ion(param1, param2);"
    >
    >The error I get with this is that it does the javascript action then Submits
    >the form - I do not want it to submit, just do the javascript action.
    try

    onClick="addOpt ion(param1, param2);return( false);"


    Michael

    Comment

    • Randy Webb

      #3
      Re: image type button not starting javascript action

      Notgiven said the following on 8/7/2006 3:50 PM:
      This works:
      <input type="button" value="Add to list" onClick="addOpt ion(param1,
      param2);">
      >
      But this doesn't:
      <img src="images/add.gif" onClick="addOpt ion(param1, param2);">
      >
      The error I get using the img tag is, "this.form has no properties". Yet it
      is right beside the input tag that does work with the same OnClick= params
      That is because img elements are not part of the form so when you try to
      refer to this.form you get the error.
      This doesn't work either:
      <input type="image" src="images/add.gif" value="Add to list"
      onClick="addOpt ion(param1, param2);">
      >
      The error I get with this is that it does the javascript action then Submits
      the form - I do not want it to submit, just do the javascript action.
      That is because the default behavior for input type="image" is to submit
      the form.
      What can I do to get a graphic button that will complete the javascript
      action?
      Pass a reference to your form to the function.

      function addOption(formR ef,param,param2 ){

      }

      onclick="addOpt ion('document.m yForm',param1,p aram2)"

      Or something similar. Without seeing your function it is *impossible* to
      give a definitive answer

      --
      Randy
      comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
      Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

      Comment

      • Randy Webb

        #4
        Re: image type button not starting javascript action

        Michael A. Vickers said the following on 8/7/2006 3:57 PM:
        Notgiven wrote:
        >
        >This doesn't work either:
        ><input type="image" src="images/add.gif" value="Add to list" onClick="addOpt ion(param1, param2);"
        >>
        >The error I get with this is that it does the javascript action then Submits
        >the form - I do not want it to submit, just do the javascript action.
        >
        try
        >
        onClick="addOpt ion(param1, param2);return( false);"
        return(false)?

        return isn't a function, drop the parentheses:

        return false

        --
        Randy
        comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
        Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

        Comment

        • Notgiven

          #5
          Re: image type button not starting javascript action

          "Randy Webb" <HikksNotAtHome @aol.comwrote in message
          news:0YKdnSmm4P 4pBkrZnZ2dnUVZ_ smdnZ2d@comcast .com...
          Notgiven said the following on 8/7/2006 3:50 PM:
          >This works:
          ><input type="button" value="Add to list" onClick="addOpt ion(param1,
          >param2);">
          >>
          >But this doesn't:
          ><img src="images/add.gif" onClick="addOpt ion(param1, param2);">
          >>
          >The error I get using the img tag is, "this.form has no properties". Yet
          >it is right beside the input tag that does work with the same OnClick=
          >params
          >
          That is because img elements are not part of the form so when you try to
          refer to this.form you get the error.
          >
          >This doesn't work either:
          ><input type="image" src="images/add.gif" value="Add to list"
          >onClick="addOp tion(param1, param2);">
          >>
          >The error I get with this is that it does the javascript action then
          >Submits the form - I do not want it to submit, just do the javascript
          >action.
          >
          That is because the default behavior for input type="image" is to submit
          the form.
          >
          >What can I do to get a graphic button that will complete the javascript
          >action?
          >
          Pass a reference to your form to the function.
          >
          function addOption(formR ef,param,param2 ){
          >
          }
          >
          onclick="addOpt ion('document.m yForm',param1,p aram2)"
          >
          Or something similar. Without seeing your function it is *impossible* to
          give a definitive answer
          >
          --
          Randy
          comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
          Javascript Best Practices -
          http://www.JavascriptToolbox.com/bestpractices/
          Randy - that worked perfectly - many thanks!


          Comment

          Working...