Button.value

I have a button on my page with a value that I want

<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

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.


<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.


var button = document.getElementById('bookmark');
var buttonValue = button.value;
alert(buttonValue);

paul_wilkins you are awesome. As you can see am still working on my bookmark. I had to rethink my approach.