kvnirvana Posted August 17, 2010 Share Posted August 17, 2010 Can someone please tell me why the fourth drop down wont populate? I think it is something to do with the ajax part <script language="javascript"> function reload(form){ var val=form.behan.options[form.behan.options.selectedIndex].value; var val2=form.omraede.options[form.omraede.options.selectedIndex].value; var val3=form.navn.options[form.navn.options.selectedIndex].value; self.location='perfekt.php?behan=' + val +'&omraede=' + val2 +'&navn=' + val3 ; } </script> <div class="content_top"></div> <div class="content_only"> <?php $dbservertype='mysql'; // hostname or ip of server $servername='localhost'; $dbusername='****'; $dbpassword='****'; $dbname='****'; //////////////////////////////////////// ////// DONOT EDIT BELOW ///////// /////////////////////////////////////// connecttodb($servername,$dbname,$dbusername,$dbpassword); function connecttodb($servername,$dbname,$dbuser,$dbpassword) { global $link; $link=mysql_connect ("$servername","$dbuser","$dbpassword"); if(!$link){die("Could not connect to MySQL");} mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error()); } if (isset($_POST['submit'])) ?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table width='100%' align='center' valign='center'> <tr> <td colspan='2' align='center' style='font-family:verdana;font-size:130%;'><strong> </strong><br></br></td> </tr> <th align="left" scope="col"> </table> <?php @$cat=$_GET['behan']; @$catt=$_GET['omraede']; @$cattt=$_GET['navn']; @$catttt=$_GET['id']; /* if(strlen($cat) > 0 and !is_numeric($cat)){ echo "Data Error"; exit; } */ $quer1=mysql_query("SELECT DISTINCT behan FROM be order by id"); if(isset($cat) and strlen($cat) > 0){ $quer2=mysql_query("SELECT distinct omraede FROM be WHERE behan='$cat' order by id"); } if(isset($catt) and strlen($catt) > 0){ $quer3=mysql_query("SELECT distinct navn FROM be WHERE behan='$cat' and omraede='$catt' order by id"); } if(isset($cattt) and strlen($cattt) > 0){ $quer4=mysql_query("SELECT postnr FROM be WHERE behan='$cat' and omraede='$catt' and navn='$cattt' order by id"); } // First drop down echo "<table width='50%' style='position:absolute;left:545px;top:70px;width:100%;height:100%'>"; echo "<tr>"; echo "<td style='font-family:verdana;font-size:110%;'>Vælg område:</td>"; echo "<select name='behan' onchange=\"reload(this.form)\"><option value=''>behan</option>"; while($noticia2 = mysql_fetch_array($quer1)) { if($noticia2['behan']==@$cat){ echo "<option selected value='$noticia2[behan]'>$noticia2[behan]</option>"; }else{ echo "<option value='$noticia2[behan]'>$noticia2[behan]</option>"; } } echo "</select>"; echo "<td"; echo "<tr>"; // Second drop down echo "<br>"; echo "<br>"; echo "<tr>"; echo "<td style='font-family:verdana;font-size:110%;'>Vælg område:</td>"; echo "<select name='omraede' onchange=\"reload(this.form)\"><option value=''>Vælg område</option>"; while($noticia3 = mysql_fetch_array($quer2)) { if($noticia3['omraede']==@$catt){ echo "<option value='$noticia3[omraede]'>$noticia3[omraede]</option>"; }else{ echo "<option value='$noticia3[omraede]'>$noticia3[omraede]</option>"; } } echo "</select>"; echo "<td"; echo "<tr>"; // Third drop down echo "<br>"; echo "<br>"; echo "<tr>"; echo "<td style='font-family:verdana;font-size:110%;'>Vælg navn:</td>"; echo "<select name='navn' onchange=\"reload(this.form)\"><option value=''>Vælg navn</option>"; while($noticia4 = mysql_fetch_array($quer3)) { if($noticia4['navn']==@$cattt){ echo "<option value='$noticia4[navn]'>$noticia4[navn]</option>"; }else{ echo "<option value='$noticia4[navn]'>$noticia4[navn]</option>"; } } echo "</select>"; echo "<td"; echo "<tr>"; echo "<br>"; echo "</table>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<table>"; echo "<DIV style='position:absolute;center:0px;top:0px;width:100%;height:100%;z-index:1' align='left'><TABLE width='100%' height='100%' border='0' cellpadding='0' cellspacing='1'><TR><TD align='left' valign='top' width='100%' height='40'><FONT style='font-size:16px' color='#000000' face='Arial'><B><hr></B></FONT></TD></TR></TABLE></DIV>"; echo "</table>"; // Fourth drop down echo "<table width='50%' style='position:absolute;left:545px;top:370px;width:100%;height:100%'>"; echo "<td style='font-family:verdana;font-size:110%;'>bb:</td>"; echo "<tr>"; echo "<select name='postnr'><option value=''>Vælg postnr</option>"; while($noticia5 = mysql_fetch_array($quer4)) { if($noticia5['postnr']==@$cattt){ echo "<option value='$noticia5[postnr]'>$noticia5[postnr]</option>"; }else{ echo "<option value='$noticia5[postnr]'>$noticia5[postnr]</option>"; } } echo "</select>"; echo "<td"; echo "<tr>"; echo "<table>"; ?> Quote Link to comment Share on other sites More sharing options...
radar Posted August 18, 2010 Share Posted August 18, 2010 Well aside from this not being true ajax, since the point of ajax is to not have the screen refresh and you have reload(this.form) repeatedly... you should have a few different functions for each dropdown in a different javascript file that you include into your html file.. then you have your functions that the javascript file calls, in a php file that isn't called by anything but the javascript file... i personally use switches for that with that out of the way, have you tried to echo out $noticia5? perhaps putting in (after the last echo"</select>" echo "<pre>"; print_r($noticia5); echo "</pre>" will give you some insights as to what is going on with it... Quote Link to comment Share on other sites More sharing options...
kvnirvana Posted August 18, 2010 Author Share Posted August 18, 2010 When I try to echo $quer5 it comes up with this message, but I don't know why? Undefined variable: quer5 Quote Link to comment Share on other sites More sharing options...
radar Posted August 18, 2010 Share Posted August 18, 2010 thats because you dont have a $quer5, your $noticia5, uses $quer4 so try to echo that out and see what you come up with. Quote Link to comment Share on other sites More sharing options...
kvnirvana Posted August 18, 2010 Author Share Posted August 18, 2010 I think there is something wrong with this part <script language="javascript"> function reload(form){ var val=form.behandler.options[form.behandler.options.selectedIndex].value; var val2=form.omraede.options[form.omraede.options.selectedIndex].value; var val3=form.navn.options[form.navn.options.selectedIndex].value; self.location='perfekt.php?behandler=' + val +'&omraede=' + val2 +'&navn=' + val3 ; } </script> When using the drop downs the url changes like this for the first drop down perfekt.php?behan=Ki&omraede=&navn= For the second drop down perfekt.php?behan=Ki&omraede=kbh&navn= But when I use the third drop down it's like the second value is lost it show this perfekt.php?behan=Ki&omraede=&navn=Per%20Hansen Quote Link to comment Share on other sites More sharing options...
kvnirvana Posted August 20, 2010 Author Share Posted August 20, 2010 Any suggestions? Quote Link to comment Share on other sites More sharing options...
radar Posted August 20, 2010 Share Posted August 20, 2010 alert all of these: form.behandler.options.selectedIndex form.omraede.options.selectedIndex form.navn.options.selectedIndex somewhere along the lines omraede is getting lost. 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.