Jump to content

button value script


erik

Recommended Posts

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

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>

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

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

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 by scott100
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...