168
rated 0 times
[
170]
[
2]
/ answers: 1 / hits: 41862
/ 11 Years ago, tue, august 27, 2013, 12:00:00
I was trying to figure out how to auto-populate the input value base on what was entered in another input field using javascript. Here's my code:
<script>
add = document.getElementById('address').value;
city = document.getElementById('city').value;
state = document.getElementById('state').value;
zip = document.getElementById('zip').value;
compAdd = add+ +city+ +state+ +zip;
function showAdd(){
document.getElementById('shipadd1').value=compAdd;
document.getElementById('add1').innerHTML=compAdd;
}
</script>
<form action= onchange=showAdd();>
Home Address: <input id=address name=address type=text /><br/>
Apt or Suite Number: <input id=suite name=suite type=text /><br/>
City/Town: <input id=city name=city type=text /><br/>
State:<select id=state name=state value=>...</select><br/>
Zip:<input id=zip name=zip type=text value=/><br/>
<p> Select Shipping Address Below: </p>
<input type=checkbox id=shipping-address-1 name=address1 value=><span id=shiadd1>(Print auto-populated shipping address here...)</span>
<input type=checkbox id=shipping-address-2 name=address2 value=>ABC Corp 123 Main Street, My City, State Zip
</form>
More From » jquery