•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 375,194 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,174 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 675 | Replies: 6 | Solved
![]() |
Hi Guys, the problem im having is constructing a function that is usable for any submit button if it meets a certain criteria (this case mouseOver). Now orginally I was using the submit button for only one and was working fine but there are three. So I would like to make a javascript function that allows them to change color individually and not all at the same time.
Thanks for the help in advance, Regards X =)
Thanks for the help in advance, Regards X =)
<input value="1" onMouseOver="submitOver()" type="submit" name="input_submit">
<input value="2" onMouseOver="submitOver()" type="submit" name="input_submit">
<input value="3" onMouseOver="submitOver()" type="submit" name="input_submit">
function mouseOver() {
document.getElementById("input_submit").style.color = "#00FF00"; sorry wrong code just fixed it up there:
<input value="1" onMouseOver="mouseOver()" type="submit" name="input_submit">
<input value="2" onMouseOver="mouseOver()" type="submit" name="input_submit">
<input value="3" onMouseOver="mouseOver()" type="submit" name="input_submit">
function mouseOver() {
document.getElementById("input_submit").style.color = "#00FF00";
} Hi Guys, the problem im having is constructing a function that is usable for any submit button if it meets a certain criteria (this case mouseOver). Now orginally I was using the submit button for only one and was working fine but there are three. So I would like to make a javascript function that allows them to change color individually and not all at the same time.
Thanks for the help in advance, Regards X =)
Thanks for the help in advance, Regards X =)
<input value="1" onMouseOver="mouseOver()" type="submit" name="input_submit">
<input value="2" onMouseOver="mouseOver()" type="submit" name="input_submit">
<input value="3" onMouseOver="mouseOver()" type="submit" name="input_submit">
function mouseOver() {
document.getElementById("input_submit").style.color = "#00FF00";
}•
•
Join Date: Dec 2007
Location: www.JavaScriptBank.com
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 1
the name of input tags must be unique if you want to change color individually and not all at the same time
www.JavaScriptBank.com - 2.000+ free JavaScripts
Start hosting from: $22/year | With promo code: 97USDD | At DreamHost
Start hosting from: $22/year | With promo code: 97USDD | At DreamHost
•
•
Join Date: Jan 2008
Posts: 35
Reputation:
Rep Power: 1
Solved Threads: 5
Hi OmniX,
Your code has a few problems. First, you are retrieving the Id, not the name ("document.getElementById"), so the controls will not be found properly. Second, since they all have the same name, the code won't know which one to modify. A better approach is to pass a reference to "this", which means the HTML control that actually called the function:
~ mellamokb
Your code has a few problems. First, you are retrieving the Id, not the name ("document.getElementById"), so the controls will not be found properly. Second, since they all have the same name, the code won't know which one to modify. A better approach is to pass a reference to "this", which means the HTML control that actually called the function:
<input value="1" onMouseOver="mouseOver(this)" type="submit" name="input_submit">
<input value="2" onMouseOver="mouseOver(this)" type="submit" name="input_submit">
<input value="3" onMouseOver="mouseOver(this)" type="submit" name="input_submit">
function mouseOver(theElement) {
theElement.style.color = "#00FF00";
}~ mellamokb
•
•
•
•
Hi OmniX,
Your code has a few problems. First, you are retrieving the Id, not the name ("document.getElementById"), so the controls will not be found properly. Second, since they all have the same name, the code won't know which one to modify. A better approach is to pass a reference to "this", which means the HTML control that actually called the function:
<input value="1" onMouseOver="mouseOver(this)" type="submit" name="input_submit"> <input value="2" onMouseOver="mouseOver(this)" type="submit" name="input_submit"> <input value="3" onMouseOver="mouseOver(this)" type="submit" name="input_submit"> function mouseOver(theElement) { theElement.style.color = "#00FF00"; }
~ mellamokb
mellamokb, this was the concept that I was thinking of but couldnt get it down on paper.
Works perfectly, Thanks. =)
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
ajax asp cross-browser javascript menu with few lines of code developer development firefox home html internet javascript javascript smooth scrolling scroll smoothly window document position javascript tab menu with rounded corners generator microsoft msdn office prevent javascript menu from getting hidden under flash movies site software sql vista web
- database connection(select ,insert query) within javascript function (JSP)
- Javascript function to switch Classes??? (JavaScript / DHTML / AJAX)
- Calling C# function(code behind) from javascript function (ASP.NET)
- Javascript Function Link (JavaScript / DHTML / AJAX)
- Javascript Function to reload DOM Element? (JavaScript / DHTML / AJAX)
- Trying to get a javascript function to play a sound (JavaScript / DHTML / AJAX)
- Writing a javascript function (JavaScript / DHTML / AJAX)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Cant get the cell values,please help,thanks.
- Next Thread: problems with Spry/Ajax


Linear Mode