Reputation: 2410
As the title says I have a form for an address and a form for another address, both forms have the same fields.
When one form is filled a want the user to be able to check a box to copy the form data over to the other form as these will be the same values alot of the time.
I have all the text fields working, I'm just stuck with the dropdown menu for country.
JAVASCRIPT
<script language="javascript" type="text/javascript">
function CopyAddress(f) {
var SelCountry = document.getElementById("dCountry");
var SelAccCountry = document.getElementById("dAccCountry");
if (f.cCopyAddress.checked == true) {
f.tAccAddress1.value = f.tAddress1.value;
f.tAccAddress2.value = f.tAddress2.value;
f.tAccTown.value = f.tTown.value;
f.tAccCounty.value = f.tCounty.value;
f.tAccPostcode.value = f.tPostcode.value;
f.tAccTel.value = f.tTel.value;
f.tAccFax.value = f.tFax.value;
f.tAccEmail.value = f.tEmail.value;
SelAccCountry.options[SelAccCountry.selectedIndex].value = SelCountry.options[SelCountry.selectedIndex].value;
}
}
</script>
<asp:CheckBox ID="cCopyAddress" runat="server" onclick="CopyAddress(this.form)" CssClass="autoWidth" />
If you would like me to past in the form code then just let me know but I didn't think it would be required as i don't think the error lies there.
Upvotes: 0
Views: 3221
Reputation: 1958
<script type="text/javascript">
function doit() {
document.getElementById("two").value = document.getElementById("one").value;
}
</script>
<textarea id="one">text goes here</textarea>
<input name="Checkbox1" type="checkbox" onchange="doit()" />
<textarea id="two"></textarea>
Upvotes: 2
Reputation: 27765
Just assign selectedIndex
property.
SelAccCountry.selectedIndex = SelCountry.selectedIndex;
Upvotes: 2