I'm trying to concat city, state and zip input fields that are automatically populated when the user makes a selection from a customer dropdown list and causes the address line to also change (auto populate).
I have tried all of the suggestions made in the following posts, but none of them worked as none of them have an 'accepted' answer:
Concatenate multiple HTML text inputs with stored variable, Concatenate two text fields in html, and How to concat strings from inputs with javascript?
This is my current code that displays the input box, but none of the values are showing up in it. When I get this working, I intend to 'hide' the city, state, zip inputs, so that only the concatenated input line appears on the page.
echo '<input style="float:left; margin-left:182px; margin-top:-6px; border:0px; background:none; box-shadow:none;" type="text" id="city" name="city" readonly="readonly" value="">';
echo '<input style="float:left; border:0px; margin-top:-6px; background:none; box-shadow:none;" type="text" id="state" name="state" readonly="readonly" value="">';
echo '<input style="float:left; border:0px; margin-top:-6px; background:none; box-shadow:none;" type="text" id="zip" name="zip" readonly="readonly" value="">';
echo '<input type="text" id="custAdd" name="custAdd">';
<script>
$("custAdd").change(function(){
document.getElementById('custAdd').value =
document.getElementById('city').value + ', ' +
document.getElementById('state').value + ' ' +
document.getElementById('zip').value;
};
</script>
Thanks in advance for your time and any advice you can provide.
#followed by the ID in question. So, to access thecustAddinput, you need to use$("#custAdd"), not$("custAdd").changefunction on an input, you are indicating that you want the provided handler (your internal function) to be called whenever that input is changed. So, what you've said here is that when thecustAddinput is changed (by the user typing in it, for example), the value should be changed to the values of the city, state and zip. That's surely not what you intend.