0

Is the form below a valid method of changing the id of an XHTML element, specifically the one actually being referenced? It does not seem to work for me.

document.getElementById("Original_Name").setAttribute("id", "New_name");
2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by mairtinomarta
0

Is this your way of saying that you don't know if it's possible to change the id of an element?

Situation is as follows:

Jsp uses xsl to render xhtml. I use java helper method in xsl to create a number of <option> elements inside a <select>. I want to swap / replace this <select> with an <input type="text"> according to an <option> selected by the user in another <select>. For the purposes of submitting the form, the <select> or the <input type="text"> need to be a particular id. Thus, I need to set the id of the elements as one becomes active and visible, whilst the other is hidden and inactive.

If it is not possible to change the id of an element then obviously I will look at another way of doing this.

0

No, it's very possible but it's just a plain bad idea. IDs are unique identifiers for the DOM, changing the ID is like giving your social security number to someone else; sure it might work but it's bound to cause issues.

Use css to hide/show either the select or the input and update whatever function is dependent on the ID to support two separate IDs.

Is this your way of saying that you don't know if it's possible to change the id of an element?

Situation is as follows:

Jsp uses xsl to render xhtml. I use java helper method in xsl to create a number of <option> elements inside a <select>. I want to swap / replace this <select> with an <input type="text"> according to an <option> selected by the user in another <select>. For the purposes of submitting the form, the <select> or the <input type="text"> need to be a particular id. Thus, I need to set the id of the elements as one becomes active and visible, whilst the other is hidden and inactive.

If it is not possible to change the id of an element then obviously I will look at another way of doing this.

1

Good call, I can give the two inputs other ids, and then have a third hidden field with the required id. On form submission, set the third fields value to which ever of the other two has a value! Nice one! Thanks!

Votes + Comments
Nice, thinking-for-yourself win.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.