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


In my HTML form, I have a heap of HTML text boxes (more than 2) when the id attribute is empty for the first time The HTML page loads. But when the user clicks on a text box, the ID must be "active". Others should be empty when the user clicks on the other, the id of the previous text box must be empty. The id of the new text box must be "active"

  & lt; Input type = "text" name = "test" id = "active" & gt; & Lt; Input type = "text" name = "test" id = "" & gt; & Lt; Input type = "text" name = "test" id = "" & gt; & Lt; Input type = "text" name = "test" id = "" & gt; & Lt; Input type = "text" name = "test" id = "" & gt; & Lt; Input type = "text" name = "test" id = "" & gt;   

How can I do this using JavaScript? Can anyone help me solve this matter?

Thanks and relation, Chirantaka.

Try it out, this is a pure JavaScript solution.

  & lt; Html & gt; & Lt; Top & gt; & Lt; Script & gt; Function changeIds (selectedEle) {var element = document.getElementsByName ("test"); (Var index = 0; index & lt; elements.length; index ++) {elements [index] .id = ""; } SelectedEle.id = "active"; } & Lt; / Script & gt; & Lt; Body & gt; & Lt; Form id = "myForm" & gt; & Lt; Input type = "text" onclick = "changeIds (this)" name = "test" id = "active" & gt; & Lt; Input type = "text" onclick = "changeIds (this)" name = "test" id = "" & gt; & Lt; Input type = "text" onclick = "changeIds (this)" name = "test" id = "" & gt; & Lt; Input type = "text" onclick = "changeIds (this)" name = "test" id = "" & gt; & Lt; Input type = "text" onclick = "changeIds (this)" name = "test" id = "" & gt; & Lt; Input type = "text" onclick = "changeIds (this)" name = "test" id = "" & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt;    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -