| | |
Javascript Function
Please support our JavaScript / DHTML / AJAX advertiser: 50% off 6 Months Dedicated Server Hosting from 1&1!
Thread 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 =)
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<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:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<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 =)
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<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"; }
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:
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:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<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:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<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
Works perfectly, Thanks. =)
![]() |
Similar Threads
- 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
Views: 1109 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
8 ad ajax ajaxcode ajaxhelp ajaxjspservlets animate api array asp asp.net autocomplete autoplay box boxes bug captchaformproblem catch code content cookies css date db dependent design display div dom dynamic element embed error eventhandlers events explorer ext file firefox firehose flash focus font form function google gxt hide html ie7 iframe image image() internet internet-explorer java javascript javascripts jquery js libcurl lists load maps matrixcaptcha media modal mysql objects onclick onmouseover parameters paypal php player position post resize reveal script scroll search select show simple size smarty sources sqlite text textbox toggle twitter unicode upload variables web webkit window xml





