BuildMyWeb Posted November 23, 2013 Share Posted November 23, 2013 (edited) i have some javascript referenced in an external file that is working great in FF, Chrome, and Safari, but not IE 9. when i click on the radio buttons (id=input_signup and id=input_donation), one of two block elements should display, and the other hide. i believe i have javascript properly enabled in IE. any thoughts? my js is not the best window.onload = init_all; function init_all() { // stop script if getElementById not working in this browser if( !document.getElementById ) alert('Please turn on Javascript to use this site properly.'); var input_signup = document.getElementById("input_signup"); var input_donation = document.getElementById("input_donation"); var sponsor_yes = document.getElementById("sponsor_yes"); var sponsor_no = document.getElementById("sponsor_no"); // run through the show_hide function checks when page loads set_events(); } // close init_all // show_hide_functions function set_events() { input_signup.onclick = show_signup; input_donation.onclick = show_donate; sponsor_yes.onclick = show_sponsor; sponsor_no.onclick = hide_sponsor; // in case page is refreshed or we come back via php header(), stay with form we were on if( input_signup.checked ) show_signup(); if( input_donation.checked ) show_donate(); } // close function show_hide() function show_signup() { var form_signup = document.getElementById("form_signup"); var form_donate = document.getElementById("form_donate"); form_signup.style.display = 'block'; form_donate.style.display = 'none'; } function show_donate() { var form_signup = document.getElementById("form_signup"); var form_donate = document.getElementById("form_donate"); form_signup.style.display = 'none'; form_donate.style.display = 'block'; } function show_sponsor() { var cell_sponsor = document.getElementById("td_sponsor_name"); cell_sponsor.style.display = 'block'; } function hide_sponsor() { var cell_sponsor = document.getElementById("td_sponsor_name"); cell_sponsor.style.display = 'none'; } and the HTML form: <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post"> Sign-up for the event ($25 fee per entrant): <input type="radio" name="reg_type" id="input_signup" <?php if( $_SESSION['form_version'] == "signup" ){ echo"checked='checked'"; } ?> /> | Donation Only: <input type="radio" name="reg_type" id="input_donation" <?php if( $_SESSION['form_version'] == "donate" ){ echo"checked='checked'"; } ?> /> </form> Edited November 23, 2013 by BuildMyWeb Quote Link to comment Share on other sites More sharing options...
BuildMyWeb Posted November 24, 2013 Author Share Posted November 24, 2013 as a follow up, i think it is the onclick event that is failing in IE. i put an alert() as the first statement in the show_signup function and cannot trigger it in IE tho it triggers in the other major browsers listed above. am i doing this wrong? function set_events() { input_signup.onclick = show_signup; input_donation.onclick = show_donate; Quote Link to comment Share on other sites More sharing options...
kicken Posted November 24, 2013 Share Posted November 24, 2013 You need to define input_signup, input_donation etc before you can do anything with them. Right now, you have not defined them anywhere so trying to use them will result in an error. Note that your definitions within the init_all function do not count because they are local to that function and only valid within that function. You need to re-define them in your set_events function before you can set the onclick property. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.