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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    166
    Thanks
    9
    Thanked 4 Times in 4 Posts

    Button 'value' attribute & IE

    Was anyone else aware that IE doesn't send button "value"'s?

    For example:
    HTML:
    <button name="button" type="submit" value="true">Click me</button>

    PHP:
    PHP Code:
    if ($_POST['button'] == "true")
    {
      echo 
    'button was pushed.';

    If you're in IE, nothing will happen; if in any other standard-compliant browser, "button was pushed" will be echoed. Perhaps I'm missing something, but these are just my findings.

  • #2
    Regular Coder BoldUlysses's Avatar
    Join Date
    Jan 2008
    Location
    Winston-Salem, NC
    Posts
    938
    Thanks
    10
    Thanked 190 Times in 187 Posts
    http://www.w3schools.com/tags/tag_button.asp

    Important: Be careful when using the button element in an HTML form. In a form the different browsers will submit different values. Internet Explorer will submit the text between the <button> and </button> tags, while other browsers will submit the content of the value attribute. When in a form, use the <input> tag instead.

    Note: The type attribute for the button should always be specified. The default type for Internet Explorer is "button", while in other browsers (and the W3C specification) it is "submit".
    matt | design | blog

  • #3
    Regular Coder
    Join Date
    Dec 2006
    Posts
    166
    Thanks
    9
    Thanked 4 Times in 4 Posts
    Ahh, thanks for clearing that up .

    While I'm on the topic, is there any way to submit a value different from the button's text value (in all browsers)? The only way I would think of doing this is to use javascript to change the text on the button right before submission.

    No particular reason why I want to know this, but I think it's pertinent.

  • #4
    The Apostate Apostropartheid's Avatar
    Join Date
    Oct 2007
    Posts
    3,215
    Thanks
    16
    Thanked 265 Times in 263 Posts
    Quote Originally Posted by 194673 View Post
    Ahh, thanks for clearing that up .

    While I'm on the topic, is there any way to submit a value different from the button's text value (in all browsers)? The only way I would think of doing this is to use javascript to change the text on the button right before submission.

    No particular reason why I want to know this, but I think it's pertinent.
    Why not use a hidden value?
    Code:
    <form action="post.php" method="post">
      <fieldset>
        <input type="hidden" id="session-id" name="session-id" value="192034"/>
        <label for="name">Name</label>
        <input type="text" id="name" name="name"/>
        <input type="submit" value="Post!"/>
      </fieldset>
    </form>


  •  

    Posting Permissions

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