I want to set data-value of text box with the value of itself and the value of another input box. I have written simple javascript snippet to handle this at oninput attribute, but it is not updating the data-value attribute with the expected value.
<form onsubmit="return false" >
First name : <input type="text" name="txtFirstName" data-value="" oninput="txtFirstName.data-value = txtFirstName.value +' '+ txtLastName.value"/> <br><br>
Last name : <input type="text" name="txtLastName" oninput="txtFirstName.data-value = txtFirstName.value +' '+ txtLastName.value"/>
You need to use dataset.value
instead of data-value
. For more info about accessing data attribute value visit here.
<form onsubmit="return false">
First name :
<input type="text" name="txtFirstName" data-value="" oninput="txtFirstName.dataset.value = txtFirstName.value +' '+ txtLastName.value" />
<br>
<br>Last name :
<input type="text" name="txtLastName" oninput="txtFirstName.dataset.value = txtFirstName.value +' '+ txtLastName.value" />
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments