erik Posted March 31, 2006 Share Posted March 31, 2006 Hello, sorry if this is the wrong part of the forum. I want to use a script with the button tag to ad text to the button. The www and google didn't give the answer.<button>some script to place the button text</button> Link to comment Share on other sites More sharing options...
scott100 Posted March 31, 2006 Share Posted March 31, 2006 Hello, sorry if this is the wrong part of the forum. I want to use a script with the button tag to ad text to the button. The www and google didn't give the answer.<button>some script to place the button text</button><{POST_SNAPBACK}> Welcome to forum and don't worry this is the correct part is this what you are looking for, change the button value in this case depending on what the user types?Enter text here: <input type="text" id="txtbox" /><br /><br />Change my value: <input type="button" value="change" onclick="this.value=txtbox.value" /> Link to comment Share on other sites More sharing options...
erik Posted March 31, 2006 Author Share Posted March 31, 2006 Thanks for the help. But this is not what I had in mind. I realise that my question was not complete. I want to place the text for the buttons in a separate file.So each button with ID=1 has the text OK, each button with ID=2 the text wrong.somthing like this. Link to comment Share on other sites More sharing options...
scott100 Posted March 31, 2006 Share Posted March 31, 2006 (edited) You are not allowed to use an id more than once, an id must be unique.You could maybe do this using classes, i will check it out Edited March 31, 2006 by scott100 Link to comment Share on other sites More sharing options...
scott100 Posted March 31, 2006 Share Posted March 31, 2006 Ok this does what you want, only it uses classes instead of id's <html><head><script type="text/javascript">function classAction(theClass){ var allTags = document.getElementsByTagName('*'); for(i=0; i<allTags.length; i++) { if(allTags[i].className == theClass) allTags[i].value="ok"; }}function classAction2(theClass){ var allTags = document.getElementsByTagName('*'); for(i=0; i<allTags.length; i++) { if(allTags[i].className == theClass) allTags[i].value="wrong"; }}</script></head><body><input type="button" class="1" value="1" /><br /><input type="button" class="1" value="1" /><br /><input type="button" class="1" value="1" /><br /><br /><input type="button" class="2" value="2" /><br /><input type="button" class="2" value="2" /><br /><input type="button" class="2" value="2" /><br /><br /><input type="button" value="change" onclick="classAction('1');classAction2('2')" /></body></html> Link to comment Share on other sites More sharing options...
erik Posted April 3, 2006 Author Share Posted April 3, 2006 Scott Thanks for your help. I think this will do.Thanks Erik Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now