Javascript: how to change form fields value with single click -
I am trying to set the value of three different input text fields with an onclick function.
I have an image with this image ...
& lt; Img src = "images / delete_row.png" width = "25" onClick = "clear (0);" / & Gt;
And I have three input text fields in which everyone has the ID of "0".
When I click on my image, I want to set the value of all the three fields
Thanks! First, you should have your own id
values separated by
. You should never be on the same page twice on the same ID Use it as an example HTML:
& lt; Input type = "text" id = "name_0" name = "name" /> & Lt; Input type = "text" id = "phone_0" name = "phone" /> & Lt; Input type = "text" id = "email_0" name = "email" />
You can use this JavaScript function:
& lt; Script type = 'text / javascript' & gt; Function empty row (id) {var name = document.getElementById ('name_' + ID), phone = document.getElementById ('phone_' + ID), email = document.getElementById ('email_' + ID); // clear value name.value = phone.value = email.value = ""; } & Lt; / Script & gt;
and your img
tag will remain unchanged:
& lt; Img src = "images / delete_row.png" width = "25" onclic = "clear (0);" / & Gt;
Comments
Post a Comment