What's the cleanest way, like 1 line of JavaScript code, to set one text box's text property to equal another?
e.g. the JavaScript way to accomplish this:
txtShipCity.Text = txtCity.Text;
Thanks!
In JavaScript:
document.getElementById('txtShipCity').value = document.getElementById('txtCity').value;
Sweeten it with jQuery:
$('#txtShipCity').val($('#txtCity').val());
Although you will probably have to use the ClientID
s of the two textboxes, so your JS might end up looking pretty nasty, like:
document.getElementById('<%= txtShipCity.ClientID %>').value = document.getElementById('<%= txtCity.ClientID %>').value;
Providing you have id
attributes on the textboxs you could easily have a one-liner in jQuery doing the following:
$("#txtShipCity").text($("#txtCity").text());
(or $("#txtShipCity").val($("#txtCity").val());
if you are dealing with an input
)
If jQuery isn't really an option then try
document.getElementById("txtShipCity").value = document.getElementById("txtCity").value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With