Updating data-value of input text box oninput not working

user1614862

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"/>

JSFiddle

Pranav C Balan

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.

edited at
0

Comments

0 comments
Login to comment

Related

input box not working when Oninput() calls

Javascript value not working with input text box

Blazor binding input value to oninput not working with onkeypress

ng-model and value combination not working for input text box

Not Updating setTimeout() value on click from input box

RSelenium: input value in text box

Get the value in an input text box

Input text box value is not changing

Edit button on GridView not updating with input box data

Changing value of a text box is not working

masked input inside xeditable text box not working

Input text box validation is not working in Vue js

Vue JS - Input value text is not updating

How to send the input text box value to angularjs onclick on the text box?

Oninput event not working when value in text field is passed from another form

angularJS input text box : default value

xslt get xml value into input text box

Change label text on Input Box value change

How to display value in nearby input text box

What is the value of an empty text input box?

Using <input oninput= ... with current value in textbox

Javascript - filtering data with text input box

Text Box Updating

FormGroup.patchValue is not updating the text box view for null value

how to get input group radio value from input text box

jQuery on change/input not working when updating value via JS

Grabbing the input value and display that as a value in another text box

Input text box binding failing to set but working on get of an Angular property

HTML input text box placeholder not working outside of Visual Studio environment