HDFilmMaker2112 Posted May 28, 2012 Share Posted May 28, 2012 The below AJAX code is not working. It's not pulling the data from the page. I've written out the variable from HTML code (i.e; document.write(signup_type); ) which prints out the right data to send via the query string to the php page, but it doesn't seem to be sending the data to the php page or receiving the response. function requestObj() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } } var http = requestObj(); function sndReq(year,month) { http.open('get', 'day_menu.php?year='+year+'&month='+month, true); http.onreadystatechange = handleResponse; http.send(null); } function handleResponse() { if(http.readyState == 4){ var response = http.responseText; document.getElementById("day").innerHTML = response; } } var http2 = requestObj(); function sendReq(signup_type) { http2.open('get', 'signup.php?signup_type='+signup_type, true); http2.onreadystatechange = handleRes; http2.send(null); } function handleRes() { if(http2.readyState == 4){ var res = http2.responseText; document.getElementById("signup_forms").innerHTML = res; } } <div class="register_ad_wrapper"> <div class="register_wrapper"> <form action=""> <div class="register_account_type_position"> <p class="signup_title">Sign-Up for - Step One</p> <p class="register_account_type_title">Account Type:</p> <span class="register_account_type_personal_position"><input type="radio" value="personal" name="register_account_type" id="register_account_type_personal" class="register_account_type_personal" onclick="sendReq(\'personal\');" '; if((isset($_SESSION['account_type']) && $_SESSION['account_type']=="personal") || !isset($_SESSION['account_type'])){ $content.='checked="checked" '; } $content.='/> <label for="register_account_type_personal"><span class="register_radio_text">Personal</span></label></span> <span class="register_account_type_music_position"><input type="radio" value="music" name="register_account_type" id="register_account_type_music" class="register_account_type_music" onclick="sendReq(\'music\');" '; if(isset($_SESSION['account_type']) && $_SESSION['account_type']=="music"){ $content.='checked="checked" '; } $content.='/> <label for="register_account_type_music"><span class="register_radio_text">Band/Recording Artist</span></label></span> <span class="register_account_type_film_position"><input type="radio" value="film" name="register_account_type" id="register_account_type_film" class="register_account_type_film" onclick="sendReq(\'film\');" '; if(isset($_SESSION['account_type']) && $_SESSION['account_type']=="film"){ $content.='checked="checked" '; } $content.='/> <label for="register_account_type_film"><span class="register_radio_text">Filmmaker/Actor</span></label></span> <span class="register_account_type_business_position"><input type="radio" value="business" name="register_account_type" id="register_account_type_business" class="register_account_type_business" onclick="sendReq(\'business\');" '; if(isset($_SESSION['account_type']) && $_SESSION['account_type']=="business"){ $content.='checked="checked" '; } $content.='/> <label for="register_account_type_business"><span class="register_radio_text">Business</span></label></span> <span class="register_account_type_other_position"><input type="radio" value="business" name="register_account_type" id="register_account_type_other" class="register_account_type_other" onclick="sendReq(\'other\');" '; if(isset($_SESSION['account_type']) && $_SESSION['account_type']=="other"){ $content.='checked="checked" '; } $content.='/> <label for="register_account_type_other"><span class="register_radio_text">Other</span></label></span> </div> <div id="signup_forms"> <div class="register_form_wrapper"> <p class="register_form_position"> <label for="register_email"><span class="register_form_text">Email:</span></label> <input type="email" value="'.$_SESSION['register_email'].'" name="register_email" id="register_email" class="register_form" /> </p> <p class="register_form_position"> <label for="register_fname"><span class="register_form_text">First Name:</span></label> <input type="text" value="'.$_SESSION['register_fname'].'" name="register_fname" id="register_fname" class="register_form" /> </p> <p class="register_form_position"> <label for="register_lname"><span class="register_form_text">Last Name:</span></label> <input type="text" value="'.$_SESSION['register_lname'].'" name="register_lname" id="register_lname" class="register_form" /> </p> <p class="register_form_position"> <label for="register_check_email"><span class="register_form_text">Re-enter Email:</span></label> <input type="email" value="'.$_SESSION['register_check_email'].'" name="register_check_email" id="register_check_email" class="register_form" /> </p> <p class="register_form_position"> <label for="register_password"><span class="register_form_text">New Password:</span></label> <input type="password" value="'.$_SESSION['register_password'].'" name="register_password" id="register_password" class="register_form" /> </p> <p class="register_form_position"> <label for="register_check_password"><span class="register_form_text">Re-enter Password:</span></label> <input type="password" value="'.$_SESSION['register_check_password'].'" name="register_check_password" id="register_check_password" class="register_form" /> </p> <p class="register_form_position_gender"> Gender: <select name="month" id="month"> <option value=""></option> <option value="Female">Female</option> <option value="Male">Male</option> </select> </p> <p class="register_form_position_birthday"> Birthday: <select name="month" id="month"> <option value="">Month</option> <option value="January">January</option> <option value="February">February</option> <option value="March">March</option> <option value="April">April</option> <option value="June">June</option> <option value="July">July</option> <option value="August">August</option> <option value="September">September</option> <option value="October">October</option> <option value="November">November</option> <option value="December">December</option> </select> <select name="day" id="day"> <option>Day</option>'."\n". $day_menu .'</select> <select name="year" id="year"> <option>Year</option>'."\n". $year_menu .'</select> </p> <p class="register_form_position"> <input type="submit" value="Sign Up for Basic Membership" class="register_button_position" /> </p> </div> </form> </div> </div> <div class="ad_wrapper"> Ad </div> </div> <?php $form_type=$_GET['signup_type']; if($form_type=="music"){ $content.='Test'; } elseif($form_type=="film"){ $content.='Test2'; } elseif($form_type=="business"){ $content.='Test3'; } elseif($form_type=="other"){ $content.='Test4'; } else{ $content.=' <div class="register_form_wrapper"> <p class="register_form_position"> <label for="register_email"><span class="register_form_text">Email:</span></label> <input type="email" value="'.$_SESSION['register_email'].'" name="register_email" id="register_email" class="register_form" /> </p> <p class="register_form_position"> <label for="register_fname"><span class="register_form_text">First Name:</span></label> <input type="text" value="'.$_SESSION['register_fname'].'" name="register_fname" id="register_fname" class="register_form" /> </p> <p class="register_form_position"> <label for="register_lname"><span class="register_form_text">Last Name:</span></label> <input type="text" value="'.$_SESSION['register_lname'].'" name="register_lname" id="register_lname" class="register_form" /> </p> <p class="register_form_position"> <label for="register_check_email"><span class="register_form_text">Re-enter Email:</span></label> <input type="email" value="'.$_SESSION['register_check_email'].'" name="register_check_email" id="register_check_email" class="register_form" /> </p> <p class="register_form_position"> <label for="register_password"><span class="register_form_text">New Password:</span></label> <input type="password" value="'.$_SESSION['register_password'].'" name="register_password" id="register_password" class="register_form" /> </p> <p class="register_form_position"> <label for="register_check_password"><span class="register_form_text">Re-enter Password:</span></label> <input type="password" value="'.$_SESSION['register_check_password'].'" name="register_check_password" id="register_check_password" class="register_form" /> </p> <p class="register_form_position_gender"> Gender: <select name="month" id="month"> <option value=""></option> <option value="Female">Female</option> <option value="Male">Male</option> </select> </p> <p class="register_form_position_birthday"> Birthday: <select name="month" id="month"> <option value="">Month</option> <option value="January">January</option> <option value="February">February</option> <option value="March">March</option> <option value="April">April</option> <option value="June">June</option> <option value="July">July</option> <option value="August">August</option> <option value="September">September</option> <option value="October">October</option> <option value="November">November</option> <option value="December">December</option> </select> <select name="day" id="day"> <option>Day</option>'."\n". $day_menu .'</select> <select name="year" id="year"> <option>Year</option>'."\n". $year_menu .'</select> </p> <p class="register_form_position"> <input type="submit" value="Sign Up for Basic Membership" class="register_button_position" /> </p> </div>'; } echo $content; ?> Quote Link to comment Share on other sites More sharing options...
requinix Posted May 28, 2012 Share Posted May 28, 2012 requestObj() doesn't return anything. Quote Link to comment Share on other sites More sharing options...
HDFilmMaker2112 Posted May 28, 2012 Author Share Posted May 28, 2012 Alright, so just return xmlhttp; Inside the RequestObj function? Doesn't seem like it did anything. Here's the modified AJAX: function requestObj() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } return xmlhttp; } var http = requestObj(); function sndReq(year,month) { http.open('get', 'day_menu.php?year='+year+'&month='+month, true); http.onreadystatechange = handleResponse; http.send(null); return false; } function handleResponse() { if(http.readyState == 4){ var response = http.responseText; document.getElementById("day").innerHTML = response; } } var http2 = requestObj(); function sendReq(signup_type) { http2.open('get', 'signup.php?signup_type='+signup_type, true); http2.onreadystatechange = handleRes; http2.send(null); } function handleRes() { if(http2.readyState == 4){ var res = http2.responseText; document.getElementById("signup_forms").innerHTML = res; } } Quote Link to comment Share on other sites More sharing options...
requinix Posted May 28, 2012 Share Posted May 28, 2012 I don't see anything obvious. Are there any JavaScript errors? Have you checked whether the AJAX call works? Put in some alert() or console.log() statements? Quote Link to comment Share on other sites More sharing options...
HDFilmMaker2112 Posted May 28, 2012 Author Share Posted May 28, 2012 Alright, I got it. I had a bunch of extra junk at the top of the Ajax.js page. Now, using the ajax functions, that weren't included in my last issue, I need a little help figuring out how to get the values from each of the Month select menu and the Year select menu into the Day function. So I can make it so if someone selects February and a leap year it place 29 into the array, and if it's February and not a leap year it keeps 29 out of the array. function requestObj() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } return xmlhttp; } var http = requestObj(); function sndReq(year,month){ http.open('get', 'day_menu.php?year='+year+'&month='+month, true); http.onreadystatechange = handleResponse; http.send(null); } function handleResponse(){ if(http.readyState == 4){ var response = http.responseText; document.getElementById("day").innerHTML = response; } } function generateBirthYearMenu($current_year){ session_start(); $earliest_year=$current_year-100; $cutoff_year=$current_year-12; $year=""; while($cutoff_year >= $earliest_year){ $year.='<option value="'.$cutoff_year.'"'; if(isset($_SESSION['birthday_year']) && $_SESSION['birthday_year']==$cutoff_year){ $year.=' selected="selected"'; } $year.='>'.$cutoff_year.'</option>'."\n"; $cutoff_year--; } return $year; } function generateBirthDayMenu($month,$year){ session_start(); $day_array=array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28); $month_array1=array("April", "June", "September", "November"); $month_array2=array("January", "March", "May", "July", "August", "October", "December"); if($month=="February" && ($year=="" || $year=null)){ } elseif($month=="February" && ($year % 4) ==0 && (($year % 100) !=0 || ($year % 400) ==0)){ array_push($day_array, "29"); } else{ array_push($day_array, "29", "30", "31"); } foreach($month_array1 as $month_value){ if($month==$month_value){ array_push($day_array, "29", "30"); } } foreach($month_array2 as $month_value){ if($month==$month_value){ array_push($day_array, "29", "30", "31"); } } foreach($day_array as $day_item){ $day.='<option value="'.$day_item.'"'; if(isset($_SESSION['birthday_day']) && $_SESSION['day']==$day_item){ $day.=' selected="selected"'; } $day.='>'.$day_item.'</option>'."\n"; } return $day; } day_menu.php <?php require_once 'function.php'; $month=$_GET['month']; $year=$_GET['year']; $form_day_menu=generateBirthDayMenu($month,$year); echo "<select name=\"day\"> <option>Day</option> $form_day_menu </select>"; ?> Quote Link to comment Share on other sites More sharing options...
HDFilmMaker2112 Posted May 28, 2012 Author Share Posted May 28, 2012 Got the last bit. Had to trigger the AJAX with the following: For Year onchange="sendReq(this.value,month.value);" For Month onchange="sendReq(year.value,this.value)"; 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.