My question is: at what point does text entered into an HTML text input field become the value of that input field?
I should note that the problem I am trying to solve is incidental (though I have included it below for the sake of context).
In the process of trying to solve this problem I realised that I needed a wider understanding of exactly what was going on, hence my more general question. I am unable to find any documentation explaining at what point text entered into a text field (or any HTML object that accepts text input) becomes part of that object (as a value, etc).
Incidental problem I am trying to solve:
I have a bunch of input[type='text']
fields on a page. Some of the fields are pre-populated with values and some have empty values (value=''
).
I have a script that prevents users from deleting or adjusting the text in the pre-populated fields but allows them to enter text in the empty fields.
However, once a user "leaves" a field, i.e. clicks outside of the field, the entered text is no longer editable, even though the value of the field does not appear to have been updated (at least as far as I can see in Chrome Developer Tools). To me, this suggests that the entered text has become the value of that field? But if that is the case, why doesn't Chrome Dev Tools reflect this?
HTML:
<form id="group-email-form">
<input type="text" value="test1@test.com">
<input type="text" placeholder="Email Address 2" value="">
</form>
jQuery:
$('#group-email-form input').on('focus', function() {
var myValue = $(this).val();
console.log(myValue);
if ( myValue == '' ) {
console.log('input has empty value');
}
else {
console.log('input has a value');
$(this).keydown( function (e) {
var keyCode = e.keyCode || e.which;
if ( keyCode == 9 ) {
}
else {
return false;
}
});
}
});