Jump to content

chipowski

Members
  • Posts

    24
  • Joined

  • Last visited

    Never

Everything posted by chipowski

  1. Hi. Can you repost or attach your main.php with the new function that was added. Are find course and find curr the same as when you first posted them? I just want to make sure I'm looking at the right code.
  2. The reason the query is returning nothing is because the selected values are are not posting to dd3ck.php. Not sure why this is happening at the moment.
  3. ok. no you're right - if your php does work when not posting to a div then there's something else up. i can't really look into this properly till I'm back home. will get back to you soon
  4. Or it might need to be on what I've just put on there: echo "$display_string";
  5. No worries. Well cause it's missing out the whole of the while bit I guess the query is not returning anything. But I'm also not sure the while loop is using the right syntax. Could you try changing the page to this and see what happens? <html><body> <? require "config.php"; $TERM=$_POST['TERM']; $CURR=$_POST['CURR']; $COURSE=$_POST['COURSE']; $TITLE=$_POST['TITLE']; $AUTHOR=$_POST['AUTHOR']; $PUBLISHER=$_POST['PUBLISHER']; $INSTRUCTOR=$_POST['INSTRUCTOR']; $query = "SELECT * FROM SUMMER WHERE TERM = '$TERM' AND CURR = '$CURR' AND COURSE = '$COURSE' order by INSTRUCTOR"; $qry_result = mysql_query($query) or die(mysql_error()); $display_string = ""; while($row = mysql_fetch_array($qry_result)) { $display_string .=<tr><td colspan=3><b>Instructor: $row[iNSTRUCTOR]</b></td></tr><tr><td> </td></tr><tr><td colspan=2 rowspan=4><img src=\"Merchant5/$row[thumbnail]\" /></td><td><a href=\"Merchant5/$row[TITLE]\" onclick=\"return GB_showCenter('Product', this.href)\"> $row[TITLE]</a></td></tr><tr><td>Author: $row[AUTHOR]</td></tr><tr><td>Publisher: $row[PUBLISHER] <br /> </td></tr><tr><td><a href=\"Merchant5/$row[TITLE]\" onclick=\"return GB_showCenter('Product', this.href)\"><img src=\"Merchant5/buybooksnow.png\" /></a></td></tr><tr><td colspan=3><br /><hr /><br /></td></tr> } echo "<table style='color:#fff;'>"; echo $display_string; echo "</table>"; ?> </body></html>
  6. You've put the alert in the wrong place. Can you change that last function to this: function get_Results(TERM,CURR,COURSE) { var strURL="dd3ck.php?TERM="+TERM+"&CURR="+CURR+"&COURSE="+COURSE; var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { alert("Response "+req.responseText); document.getElementById('RESULTS_div').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } }
  7. In the new function you've created, below the line: if (req.status == 200) { Could you add this line: alert("Response "+req.responseText); What is printed to screen when you submit your form?
  8. Well I can't test this out cause of work restrictions but this is what I reckon should work. First you need to create a new function under the function "function get_COURSE(CURR)". It's the same function again but calling your dd3 page and updating an additional div: function get_Results(<your variables>) { var strURL="dd3ck.php?<your variables>="+<your variables>; var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('RESULTS_div').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } Then just before the line </form> you need to add something like this: <input type="button" value="Click Here" onClick="get_Results();"> And finally add a new div. <div id="RESULTS_div"> </div> I'm pretty sure this should get you going along the right lines.
  9. I have the page loading fine here: http://www.piano-tuna.com/ajax/main.php If you look at your page source the code is being truncated at the second div. Did you try changing the curr and course div to below?: <div id="CURR_div"> </div> <div id="COURSE_div"> </div>
  10. You can see the response is coming back ok if you change the get_COURSE function to what's below. There is an extra line displaying the response text to screen: alert(req.responseText); function get_COURSE(CURR) { var strURL="findCOURSE.php?CURR="+CURR; var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { alert(req.responseText); document.getElementById('COURSE_div').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } I can get all 3 populating by changing the 2nd & 3rd divs to below: <div id="CURR_div"> </div> <div id="COURSE_div"> </div> Can't trace the problem that prevents the page working with your current code but this solution seems to work nicely. Hope this helps you out.
  11. Hi. Just managed to get the alert to work based on your very first set of code. The error is in this line: Alert("Ajax Sent"); It should be: alert("Ajax Sent"); Simply need to change the capital A of alert to lowercase. Let me know if you can get the alert message now. I've not looked into populating the second drop down as that will be very straightforward but do let me know if you need any more help.
  12. Can you post the contents of constellation.php with any db connection details removed if you are using a db connection. Also if you are using a db, can you post the values from your tables.
  13. Ok - was worth a shot. I'll have a look at this when back home - in work now so got limited access to stuff
  14. Hi. I think you simply need to defined the ajax function prior to defining the drop down contents. Try this: <html> <head> <script type="text/javascript"> function ajax(str) { if (str=="") { document.getElementById("ajaxResult").innerHTML="Constellation: <select name=\"fleetLocationConstellation\"><option value=\"\">Select Region First</option></select>"; return; } if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("ajaxResult").innerHTML=xmlhttp.responseText; } } Alert("Ajax Sent"); xmlhttp.open("GET","constellation.php?r="+str,true); xmlhttp.send(); } </script> </head> <body> <?php echo "<form name=\"createFleet\" method=\"post\" action=\"scripts/fleet.php\">"; echo "<input name=\"fleetSize\" type=\"hidden\" value=\"1\">"; echo "Fleet Location: <select name=\"fleetLocationRegion\" onchange=\"ajax(this.value)\">"; echo "<option value=\"\">Selecte Region</option>"; echo "<option value=\"aridia\">Aridia</option>"; echo "<option value=\"blackrise\">Black Rise</option>"; echo "<option value=\"derelik\">Derelik</option>"; echo "<option value=\"devoid\">Devoid</option>"; echo "<option value=\"domain\">Domain</option>"; echo "<option value=\"essence\">Essence</option>"; echo "<option value=\"genesis\">Genesis</option>"; echo "<option value=\"heimatar\">Heimatar</option>"; echo "<option value=\"kador\">Kador</option>"; echo "<option value=\"khanid\">Khanid</option>"; echo "<option value=\"korazor\">Korazor</option>"; echo "<option value=\"lonetrek\">Lonetrek</option>"; echo "<option value=\"metropolis\">Metropolis</option>"; echo "<option value=\"moldenheath\">Molden Heath</option>"; echo "<option value=\"placid\">Placid</option>"; echo "<option value=\"sinqlaison\">Sinq Laison</option>"; echo "<option value=\"solitude\">Solitude</option>"; echo "<option value=\"tashmurkon\">Tash-Murkon</option>"; echo "<option value=\"thebleaklands\">The Bleak Lands</option>"; echo "<option value=\"thecitadel\">The Citadel</option>"; echo "<option value=\"theforge\">The Forge</option>"; echo "<option value=\"vergevendor\">Verge Vendor</option>"; echo "</select>"; echo "<div id=\"ajaxResult\">"; echo "Constellation: <select name=\"fleetLocationConstellation\">"; echo "<option value=\"\">Select Region First</option>"; echo "</select>"; echo "</div>"; echo "<input name=\"submit\" type=\"submit\" value=\"Create Fleet\">"; echo "</form>"; ?> </body> </html>
  15. Hi. For the first question - I would put each drop down in it's own div and then reload the div onchange not reload the form in the same way I have done with the code posted on Aug 1 at 3:12. The line where this is done is: <select name="catId" onChange="get_subcat(this.value);get_subcat2(0)">. Can you post your db contents too - that way I could rebuild what you have so it'll be easier to help. For the second one - I'm not too sure I get you. What do you mean about submitting into an iframe?
  16. Hiya. I've got this working using the link I posted to you. Here's the code to do it. Change the hostname, username and password in the db_config file to match your database and it should work straight away. It's not the complete code - there's no submit button etc - but the functionality works without reloading the whole page. The start and end of each file is marked with ********************* just to make it easier to read on this page Hope it helps you out. Filename: db_config.php ************************************************************************* <?php $dbhost = 'hostname; $dbuser = 'username'; $dbpass = 'password'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = $dbuser; mysql_select_db($dbname); ?> ************************************************************************* Filename: main.php ************************************************************************* <html> <head> <script language="javascript" type="text/javascript"> // Roshan's Ajax dropdown code with php // This notice must stay intact for legal use // Copyright reserved to Roshan Bhattarai - nepaliboy007@yahoo.com // If you have any problem contact me at http://roshanbh.com.np function getXMLHTTP() { //fuction to return the xml http object var xmlhttp=false; try{ xmlhttp=new XMLHttpRequest(); } catch(e) { try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e1){ xmlhttp=false; } } } return xmlhttp; } function get_subcat(catId) { var strURL="findsubcat.php?catId="+catId; var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('subcat_div').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } function get_subcat2(subcatId) { var strURL="findsubcat2.php?subcatId="+subcatId; var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('subcat2_div').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } </script> </head> <body> <form method=post name=f1 action='dd3ck.php'> <div id="first_drop_down"> <select name="catId" onChange="get_subcat(this.value);get_subcat2(0)"> <option>Select one</option> <?php include ('db_connect.php'); $query=("SELECT DISTINCT cat_id, category FROM category order by category"); $result=mysql_query($query); while($row=mysql_fetch_array($result)) { ?> <option value=<?php echo $row['cat_id']?>><?php echo $row['category']?></option> <? } ?> </select> <div id="subcat_div"> <?php include ('findsubcat.php'); ?> </div> <div id="subcat2_div"> <?php include ('findsubcat2.php'); ?> </div> </body> </html> ************************************************************************* Filename: findsubcat.php ************************************************************************* <!--//---------------------------------+ // Developed by Roshan Bhattarai | // http://roshanbh.com.np | // Contact for custom scripts | // or implementation help. | // email-nepaliboy007@yahoo.com | //---------------------------------+--> <? #### Roshan's Ajax dropdown code with php #### Copyright reserved to Roshan Bhattarai - nepaliboy007@yahoo.com #### if you have any problem contact me at http://roshanbh.com.np #### fell free to visit my blog http://roshanbh.com.np ?> <? $catId=intval($_GET['catId']); include ('db_connect.php'); if ($catId!=0) { $query="SELECT DISTINCT subcategory,subcat_id FROM subcategory where cat_id='$catId' order by subcategory"; $result=mysql_query($query); } else { $query="SELECT DISTINCT subcategory,subcat_id FROM subcategory order by subcategory"; $result=mysql_query($query); } ?> <select name="subcatId" onchange="get_subcat2(this.value)"> <option>Select one</option> <? while($row=mysql_fetch_array($result)) { ?> <option value=<?=$row['subcat_id']?>><?=$row['subcategory']?></option> <? } ?> </select> ************************************************************************* Filename: findsubcat2.php ************************************************************************* <!--//---------------------------------+ // Developed by Roshan Bhattarai | // http://roshanbh.com.np | // Contact for custom scripts | // or implementation help. | // email-nepaliboy007@yahoo.com | //---------------------------------+--> <? #### Roshan's Ajax dropdown code with php #### Copyright reserved to Roshan Bhattarai - nepaliboy007@yahoo.com #### if you have any problem contact me at http://roshanbh.com.np #### fell free to visit my blog http://php-ajax-guru.blogspot.com ?> <? $subcatId=intval($_GET['subcatId']); include ('db_connect.php'); if ($subcatId!=0) { $query="SELECT DISTINCT subcat2 FROM subcategory2 where subcat_id='$subcatId' order by subcat2"; $result=mysql_query($query); } else { $query="SELECT DISTINCT subcat2 FROM subcategory2 order by subcat2"; $result=mysql_query($query); } ?> <select name="subcat2Id"> <option>Select one</option> <? while($row=mysql_fetch_array($result)) { ?> <option value=<?=$row['subcat2']?>><?=$row['subcat2']?></option> <? } ?> </select> *************************************************************************
  17. Ok I see what you mean about the reloading. I'll have a play around with your code see what I can come up with
  18. Hi. Do you mean Ontario is the 4th field you've added?
  19. Hi. I have just done this myself a few days ago. Try the site below - I have the code working perfectly. http://roshanbh.com.np/2008/01/populate-triple-drop-down-list-change-options-value-from-database-using-ajax-and-php.html This code uses hardcoded values for the first menu option which I've modified to use a mysql query instead. The only fault with the existing code is that if you change your selection on the first menu, the 3rd does not reset but I've also modified that to work too with the help of forum member radar. If you need any help adapting this code for your needs give me a shout and I'll do my best to help out
  20. sorted. got it working perfectly now. thanks so much for your help. i've been tearing my hair out trying to solve this.
  21. cool thanks for the info. i'm very new to ajax so it'll take me some time but now i know what to look into. ta
  22. Hi all. Apologies if this has been answered before but I've searched the forums and spent hours on the net going through every site listed to find out how to do this and come up with nothing so far. Does anyone have some code to refresh the content of a div based on an onChange event from a form? All I can find is a time based refresh - listed below - which does work fine. But I need the event to be user controlled rather than time based. Any help will be greatly appreciated. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script> <script> var auto_refresh = setInterval( function() { $('#loaddiv').load('data_page.php'); }, 20000); </script>
×
×
  • 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.