SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: button.value

  1. #1
    SitePoint Zealot
    Join Date
    Aug 2011
    Location
    Trinidad and Tobago
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    button.value

    I have a button on my page with a value that I want
    Code:
    <button name='bookmark' type='button' onclick='bookmark()' value='$id'>Bookmark</button>
    . I want to access this value to manipulate it in any how to do I refer to the value the code
    Code:
    alert(document.bookmark.value)
    is not working.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,682
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by skelleex View Post
    I have a button on my page with a value that I want
    Code:
    <button name='bookmark' type='button' onclick='bookmark()' value='$id'>Bookmark</button>
    . I want to access this value to manipulate it in any how to do I refer to the value the code
    Code:
    alert(document.bookmark.value)
    is not working.
    Names should only be used for Form fields that you intend to submit to the server. Use an id attribute instead, so that scripting can easily gain a reference to the element.

    Code html4strict:
    <button id='bookmark' type='button' onclick='bookmark()' value='$id'>Bookmark</button>

    Once you've done that, you can use JavaScript to gain a reference to the button, and from there to the value attribute itself.

    Code javascript:
    var button = document.getElementById('bookmark');
    var buttonValue = button.value;
    alert(buttonValue);
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2011
    Location
    Trinidad and Tobago
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    paul_wilkins you are awesome. As you can see am still working on my bookmark. I had to rethink my approach.


Bookmarks

Posting Permissions

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