Monday 15 June 2015

jquery - Switch HTML ID Attribute Value Between HTML Text-Boxes Using JavaScript -



jquery - Switch HTML ID Attribute Value Between HTML Text-Boxes Using JavaScript -

i have stack of html text-boxes (more 2) in html form. when html page loads 1st time id attribute empty. when user clicks on text-box id should "active". others should empty. when user clicks on another, previous text-box's id should empty. new text-box's id should "active".

<input type="text" name="test" id="active"> <input type="text" name="test" id=""> <input type="text" name="test" id=""> <input type="text" name="test" id=""> <input type="text" name="test" id=""> <input type="text" name="test" id="">

how can using javascript? can help me solve matter?

thanks , regards, chiranthaka.

try this, pure javascript solution.

<html> <head> <script> function changeids(selectedele) { var elements = document.getelementsbyname("test"); for(var index = 0 ; index < elements.length ; index++ ) { elements[index].id=""; } selectedele.id="active"; } </script> <body> <form id="myform" > <input type="text" onclick="changeids(this)" name="test" id="active"> <input type="text" onclick="changeids(this)" name="test" id=""> <input type="text" onclick="changeids(this)" name="test" id=""> <input type="text" onclick="changeids(this)" name="test" id=""> <input type="text" onclick="changeids(this)" name="test" id=""> <input type="text" onclick="changeids(this)" name="test" id=""> </form> </body> </html>

javascript jquery html xhtml

No comments:

Post a Comment