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
    Regular Coder
    Join Date
    Mar 2006
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 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

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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!||||

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,619
    Thanks
    0
    Thanked 645 Times in 635 Posts
    <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.

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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!||||


  •  

    Posting Permissions

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