Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename form field name using Javascript

Tags:

javascript

Can I rename a field of my form using Javascript? Like changing:

<input type="text" name="chicken" id="chicken"/>

to

<input type="text" name="horse" id="horse"/>
like image 533
Alex Avatar asked May 13 '13 11:05

Alex


1 Answers

Of course it is possible:

var field = document.getElementById("chicken");
field.id = "horse";  // using element properties
field.setAttribute("name", "horse");  // using .setAttribute() method
like image 184
VisioN Avatar answered Oct 21 '22 02:10

VisioN