Jump to content

Populating input fields with checkbox


dr.pepper

Recommended Posts

Hi

 

I have a form which contains address, town, postcode etc.

The form then has other fields called p_address, p_town, p_postcode etc.

 

If name, email, address contain a value and the user then ticks a checkbox, I want this to populate the relevant p_ field.

 

This is my code so far but it doesnt work in IE.

<script>
function check() {

if(document.getElementById('check').checked == true)
{

	if(document.getElementById('address').value != ''){
		document.getElementById('p_address').value = document.getElementById('address').value;
	}
	if(document.getElementById('town_city').value != ''){
		document.getElementById('p_town_city').value = document.getElementById('town_city').value;
	}
	if(document.getElementById('county').value != ''){
		document.getElementById('p_county').value = document.getElementById('county').value;
	}
	if(document.getElementById('postcode').value != ''){
		document.getElementById('p_postcode').value = document.getElementById('postcode').value;
	}

} else {

	document.getElementById('p_address').value = '';
	document.getElementById('p_town_city').value = '';
	document.getElementById('p_county').value = '';
	document.getElementById('p_postcode').value = '';
}

}
</script>

 

Does anyone know why IE doesnt like this??

 

Link to comment
Share on other sites

Here is the html:

 

<label for="address" class="fmlabel">Address: <span>*</span></label>
<input name="address" id="address" type="text" value="<?=stripslashes($_POST['address'])?>"/><br/>
                                    
<label for="town_city" class="fmlabel">City: <span>*</span></label>
<input name="town_city" id="town_city" type="text" value="<?=stripslashes($_POST['town_city'])?>"/><br/>
                                    
<label for="county_state" class="fmlabel">County: *</label>
<input name="county" id="county" type="text" value="<?=stripslashes($_POST['county'])?>"/><br/>

<label for="name">Tick here if billing name and address are same as above.</label>
<a style="cursor:pointer;font-size:12px;text-decoration:underline;" onclick="javascript:check();"><input id="check" name="check" type="checkbox" value="1"></a><br/>

<label for="address" class="fmlabel">Address: <span>*</span></label>
<input name="payment_address" id="p_address" type="text" value="<?=stripslashes($_POST['payment_address'])?>"/><br/>
                                    
<label for="town_city" class="fmlabel">City: <span>*</span></label>
<input name="payment_town_city" id="p_town_city" type="text" value="<?=stripslashes($_POST['payment_town_city'])?>"/><br/>
                                    
<label for="county_state" class="fmlabel">County: <span>*</span></label>
<input name="payment_county" id="p_county" type="text" value="<?=stripslashes($_POST['payment_county'])?>"/><br/>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.