HDFilmMaker2112 Posted July 16, 2011 Share Posted July 16, 2011 When I access second_credit.php by itself with a variable in the URL it generates a select menu properly. When I try to do it with an AJAX call, it doesn't work. ajax in index.php head tag <script type="text/javascript"> function requestObj() { var reqObj; var browser = navigator.appName; if(browser == "Microsoft Internet Explorer"){ reqObj = new ActiveXObject("Microsoft.XMLHTTP"); }else{ reqObj = new XMLHttpRequest(); } return reqObj; } var http = requestObj(); function sndReq(action) { http.open('get', 'second_credit.php?credit='+action, true); http.onreadystatechange = handleResponse; http.send(null); } function handleResponse() { if(http.readyState == 4){ var response = http.responseText; document.getElementById("ajaxout").innerHTML = response; } } </script> second_credit.php <?php require_once 'db_select.php'; $credit=$_GET['credit']; $sql_second_credit="SELECT * FROM $tbl_name4 WHERE item_id='Seq$credit' OR item_id='Tril$credit'"; $result_second_credit=mysql_query($sql_second_credit) or die(mysql_error()); $content.='<select name="new_credit">'; $content.='<option value="">Select Credit</option>'; while($second_row_credits=mysql_fetch_array($result_second_credit)){ extract($second_row_credits); $content.='<option value="'.ucfirst($item_id).'">'.ucfirst($position).' - Film # '.$film_number.'</option>'."\n"; } $content.='</select> '; ?> credit.php <?php session_start(); $myusername=$_SESSION['myusername2']; $mypassword=$_SESSION['mypassword2']; require_once 'db_select.php'; $content=' <div class="main"> <div class="main_header">Purchase Additional Credit</div>'; if($_GET['e']==t){ $content.='<p class="green clear"> Request Sent. You should be contact with a discounted crew credit button specifically for you, in the next two business days. </p> '; } else{ $content.=' <p> If you wish to purchase an additional credit, use the form below to select the credit you wish to buy, the name in which the original credit is listed under (as listed on the donors page), and the e-mail address in which the original purchase came from. This is a great to get your name back on the top 100 donors list. Once you submit this form, we will review the submitted material, create a new paypal purchase button specifically for you, and send you the link to that button. From there, you will be able to purchase the additional credit.'; if($_GET['e']==f){ $content.='<p class="red"> The email address you entered doesn\'t match the email in the database for this account. Please try again. <br /> If you keep having problems, please contact us at <a href="mailto:general@makethemoviehappen.com"> general@makethemoviehappen.com</a>. </p>'; } $content.=' <form action="" method="post"> <p><label>Name Credit is Listed Under:</label> <input type="text" name="name" size="30" /></p> <p><label>E-Mail of Original Purchase:</label> <input type="text" name="email" size="32" /></p> <p><label>Original Credit Purchased:</label>'; $sql_credit="SELECT $tbl_name2.credit,$tbl_name.donor_id,$tbl_name2.film_number FROM $tbl_name JOIN $tbl_name2 USING (donor_id) WHERE $tbl_name.username='$myusername' AND $tbl_name.password='$mypassword'"; $result_credit=mysql_query($sql_credit) or die(mysql_error()); $content.="<select name=\"credit\" onchange=\"sndReq('$credit');\">"; $content.='<option value="">Select Credit</option>'."\n"; while($credit_rows=mysql_fetch_array($result_credit)) { extract($credit_rows); $content.='<option value="'.$credit.'-'.$film_number.'" >'.ucwords($credit).' - Film # '.$film_number.'</option>'."\n" ; } $content.='<p><label>Second Credit to Purchase:</label> <div id="ajaxout"></div></p>'; $content.='<p><input type="submit" value="Submit" name="Submit" /></p> </form> '; } $content.=" </div> <br />"; ?> EDIT: I've traced the issue to sndReq not have value set in it, but it doesn't make sense why it's not working. Checking the source code once the page is generate (after PHP parsing) it has sndReq(''); Quote Link to comment Share on other sites More sharing options...
HDFilmMaker2112 Posted July 16, 2011 Author Share Posted July 16, 2011 It was because the $credit variable was declared after I was using it. Fix: $content.=' <form action="" method="post"> <p><label>Name Credit is Listed Under:</label> <input type="text" name="name" size="30" /></p> <p><label>E-Mail of Original Purchase:</label> <input type="text" name="email" size="32" /></p> <p><label>Original Credit Purchased:</label>'; $sql_credit="SELECT $tbl_name2.credit,$tbl_name.donor_id,$tbl_name2.film_number FROM $tbl_name JOIN $tbl_name2 USING (donor_id) WHERE $tbl_name.username='$myusername' AND $tbl_name.password='$mypassword'"; $result_credit=mysql_query($sql_credit) or die(mysql_error()); $menu_generate=""; while($credit_rows=mysql_fetch_array($result_credit)) { extract($credit_rows); $menu_generate.='<option value="'.$credit.'-'.$film_number.'" >'.ucwords($credit).' - Film # '.$film_number.'</option>'."\n" ; } $content.="<select name=\"credit\" onchange=\"sndReq('$credit');\">"; $content.='<option value="">Select Credit</option>'."\n"; $content.=$menu_generate; $content.="</select>"; $content.='<p><label>Second Credit to Purchase:</label> <span id="ajaxout"></span></p>'; $content.='<p><input type="submit" value="Submit" name="Submit" /></p> </form> '; } Quote Link to comment Share on other sites More sharing options...
HDFilmMaker2112 Posted July 16, 2011 Author Share Posted July 16, 2011 Now, my issue is that I need to place the onchange option into each <option> tag. This doesn't seem possible. When I place the onchange="sndReq('$credit')" into the <select> tag it generates only the first $credit choice into sndReq. How can I make it change based on the selection? Quote Link to comment Share on other sites More sharing options...
HDFilmMaker2112 Posted July 16, 2011 Author Share Posted July 16, 2011 found the solution. this.value in sndReq(); 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.