Web Analytics Made Easy -
StatCounter how to prevent button from posting data... - CodingForum

Announcement

Collapse
No announcement yet.

how to prevent button from posting data...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to prevent button from posting data...

    ok, i have a button on my page, and everytime i want to click to it, it goes to post data...but i want it to only perform a script, not actually post any data...

    Code:
    <input type="submit" value="Show Grins" onClick="chngGrinStyle();return false;">
    how i prevent it from posting data?

    Thanks, Justin
    http://www.effekt26.com

  • #2
    Get rid of that onclick. Add return false as the last line of the chngGrinStyle() function. Then in the open form tag add
    Code:
    onsubmit="return chngGrinStyle()"
    If done correctly the form should just run the script and not post anything.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

    Comment


    • #3
      Hi, that didnt seem to work...

      this is now my button code..
      Code:
      <input type="submit" value="Show Grins" onsubmit="return chngGrinStyle()">
      and this is my js...
      Code:
      function chngGrinStyle() {
          objDiv = document.getElementById('wp_grins2');
          
          if (objDiv.style.display == "none") {
              objdiv.style.display == "block";
          } else {
              objDiv.style.display == "none";
          }
      return false;
      }
      and that sits in a seperate js file...but i know the path of the js file works, coz if i plug it into the address bar...i can dl it..

      it still goes to post the data...

      Thanks, Justin
      http://www.effekt26.com

      Comment


      • #4
        <input type="submit"> is a button that submits the form (anything else is secondary.

        <input type=button"> is a button that does what you ask it to do and has no default action

        <button></button> can be used to create a button outside of a form
        Stephen
        Learn Modern JavaScript - http://javascriptexample.net/
        Helping others to solve their computer problem at http://www.felgall.com/

        Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

        Comment


        • #5
          I don't think you read my post too carefully. Do you not have a form tag? I said put onsubmit IN the form tag NOT the input button.
          ||||If you are getting paid to do a job, don't ask for help on it!||||

          Comment

          Working...
          X