dr.pepper Posted August 24, 2010 Share Posted August 24, 2010 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 https://forums.phpfreaks.com/topic/211621-populating-input-fields-with-checkbox/ Share on other sites More sharing options...
brianlange Posted August 24, 2010 Share Posted August 24, 2010 Can you post the html? Link to comment https://forums.phpfreaks.com/topic/211621-populating-input-fields-with-checkbox/#findComment-1103263 Share on other sites More sharing options...
brianlange Posted August 24, 2010 Share Posted August 24, 2010 It should work fine. Are you getting a javascript error? Link to comment https://forums.phpfreaks.com/topic/211621-populating-input-fields-with-checkbox/#findComment-1103291 Share on other sites More sharing options...
dr.pepper Posted August 25, 2010 Author Share Posted August 25, 2010 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 https://forums.phpfreaks.com/topic/211621-populating-input-fields-with-checkbox/#findComment-1103463 Share on other sites More sharing options...
dr.pepper Posted August 25, 2010 Author Share Posted August 25, 2010 It should work fine. Are you getting a javascript error? Yes I am getting this error: object doesnt support this property or method Link to comment https://forums.phpfreaks.com/topic/211621-populating-input-fields-with-checkbox/#findComment-1103470 Share on other sites More sharing options...
dr.pepper Posted August 25, 2010 Author Share Posted August 25, 2010 I have fixed it by changing the function name to checkBoxes because it had the same name as the actual checkbox. Link to comment https://forums.phpfreaks.com/topic/211621-populating-input-fields-with-checkbox/#findComment-1103472 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.