tags:

views:

57

answers:

1

I have this: <input type="button" value="hello"> I want to change the value with javascript so that it is value="goodbye". How do I do this?

Following @David's advice in the comments below here is the code I tried but could not get to work before posting this question:

var createBttn = document.getElementById('create');
createBttn.innerHTML = 'value="goodbye"';
+5  A: 

First you need to get a reference to the object that you want to change the value on, then assign the value property of that element, like this:

Say your element had an id of "someButton":

var btn = document.getElementById('someButton');
btn.value = 'goodbye';
Jacob Relkin
ah... ok thanks. Thats exactly what I was looking for.
chromedude
@chromedude, You should tick this answer as the accepted answer then. :)
Jacob Relkin
@Jacob, sorry about that one. I had to wait 15mins to accept it and by then I had left my computer and forgot about it.
chromedude
@chromedude, No worries! Thanks!
Jacob Relkin