| | |
chained select boxes
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Dec 2008
Posts: 12
Reputation:
Solved Threads: 0
i have tree select boxes. i fill those with data coming from a database (mysql)
i want to change the data of the last two selects regarding the selection of the first.
here is my code. it doesnt work (i used a little bit of javascript)
in head
in body
the $cat variable seems empty.
i know i may ask a lot. if it is not possible to check this code could u advice me on how can i solve this problem? (the content of one select box is geting data regarding the selection of a first select box)
i want to change the data of the last two selects regarding the selection of the first.
here is my code. it doesnt work (i used a little bit of javascript)
in head
JavaScript Syntax (Toggle Plain Text)
<SCRIPT language=JavaScript> function reload(form) { var val=form.cat.options[form.cat.options.selectedIndex].value; self.location='apousies.php?cat=' + val ; }</script>
in body
php Syntax (Toggle Plain Text)
//connect with database works fine @$cat=$_GET['cat']; @$cat=$HTTP_GET_VARS['cat']; ///////// Getting the data from Mysql table for first list box////////// $quer2=mysql_query("SELECT DISTINCT eidikotita, id_eidikotitas FROM eidikotita order by eidikotita"); ///////////// End of query for first list box//////////// if(isset($cat) and strlen($cat) > 0){ //it never gets here $quer=mysql_query("SELECT lastname, firstname, fathersname FROM members where id_eid=$cat order by lastname"); $quer1=mysql_query("SELECT mathima FROM mathimata where id_eid=$cat order by mathima"); }else{$quer=mysql_query("SELECT lastname, firstname, fathersname FROM members order by lastname"); $quer1=mysql_query("SELECT mathima FROM mathimata order by mathima"); } echo "<form method=post name=f1 action='apousies-ins.php'>"; ////////// Starting of first drop downlist ///////// echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>lessons</option>"; while($noticia2 = mysql_fetch_array($quer2)) { if($noticia2['id_eidikotitas']==@$cat){echo "<option selected value='$noticia2[id_eidikotitas]'>$noticia2[eidikotita]</option>"."<BR>";} else{echo "<option value='$noticia2[id_eidikotitas]'>$noticia2[eidikotita]</option>";} } echo "</select>"; ////////////////// This will end the first drop down list /////////// ////////// Starting of second drop downlist ///////// echo "<select name='subcat'><option value=''>Êáôáñôéæüìåíïò</option>"; while($noticia = mysql_fetch_array($quer)) { echo "<option value='$noticia[lastname], $noticia[firstname], $noticia[fathersname]'>$noticia[lastname], $noticia[firstname], $noticia[fathersname] </option>"; } echo "</select>"; ////////////////// This will end the second drop down list /////////// ////third list echo "<select name='subcat1'><option value=''>ÌÜèçìá</option>"; while($noticia = mysql_fetch_array($quer1)) { echo "<option value='$noticia[mathima]'>$noticia[mathima] </option>"; } echo "</select>"; ////////////////// This will end the third drop down list /////////// echo "</form>";
the $cat variable seems empty.
i know i may ask a lot. if it is not possible to check this code could u advice me on how can i solve this problem? (the content of one select box is geting data regarding the selection of a first select box)
Last edited by peter_budo; Sep 28th, 2009 at 2:41 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Sorry, wasn't paying attention and just realized that $cat was coming from the same page. This snippet looks a little suspicious to me ...
<option value=''>lessons</option> . Last edited by peter_budo; Sep 28th, 2009 at 2:42 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
•
•
Join Date: Dec 2008
Posts: 12
Reputation:
Solved Threads: 0
it does not work even if i put this line out.
when i pick something from first select box the form reloads. in the adress line shows my pick (ex. http//:......./bathmoi.php?cat=11, but the select box does not keep my selection and the second and third select boxes does not contain the data they should regarding my pick
the variable cat is still empty. thats why. should it be empty? someone please....
when i pick something from first select box the form reloads. in the adress line shows my pick (ex. http//:......./bathmoi.php?cat=11, but the select box does not keep my selection and the second and third select boxes does not contain the data they should regarding my pick
the variable cat is still empty. thats why. should it be empty? someone please....
I wouldn't omit that line, it may be correct I just never seen it done that way. I would typically use
<option value="lessons">lessons</option> or simply <option>lessons</option> if you don't need to assign a value. Have you tried to echo $cat to be sure it is empty? What I would do to make sure a selection reappears upon submitting the form would be something like <option selected="selected"><?=$cat?></option> <option>lessons</option> . That would ensure your select box holds your selection given $cat is not empty, and it does not appear to me that it would be. Last edited by peter_budo; Sep 28th, 2009 at 2:43 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Does this just "reload" the form, or does it actually submit it?
<select name='cat' onchange=\"reload(this.form)\"> If it is simply reloading it $cat will not contain a value. Last edited by peter_budo; Sep 28th, 2009 at 2:43 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
•
•
Join Date: Dec 2008
Posts: 12
Reputation:
Solved Threads: 0
of course i echoed the variable. it is empty for sure!
it never gets in here
i think u r right about the reload issue. it probably just reloads the form without submiting it. i did not know how could i submit the form by just picking somenthing from a select box. (it would be easy for me if i could place a submit button) how could i do that?
A! an issue is that right now when i pick something from the first select box - the form reloads, and in the adress line the $cat has value!!!
adress line after a random pick:
http://iek-kozan.koz.sch.gr/admin/ba...moi.php?cat=14
remenber the reload function
but my echoes still remains empty. i am confused. what shoul i do???
it never gets in here
PHP Syntax (Toggle Plain Text)
if(isset($cat) and strlen($cat) > 0){ //never in here!!!!! $quer=mysql_query("SELECT lastname, firstname, fathersname FROM members where id_eid=$cat order by lastname"); $quer1=mysql_query("SELECT mathima FROM mathimata where id_eid=$cat order by mathima"); }else{$quer=mysql_query("SELECT lastname, firstname, fathersname FROM members order by lastname"); $quer1=mysql_query("SELECT mathima FROM mathimata order by mathima"); }
i think u r right about the reload issue. it probably just reloads the form without submiting it. i did not know how could i submit the form by just picking somenthing from a select box. (it would be easy for me if i could place a submit button) how could i do that?
A! an issue is that right now when i pick something from the first select box - the form reloads, and in the adress line the $cat has value!!!
adress line after a random pick:
http://iek-kozan.koz.sch.gr/admin/ba...moi.php?cat=14
remenber the reload function
PHP Syntax (Toggle Plain Text)
<SCRIPT language=JavaScript> function reload(form) { var val=form.cat.options[form.cat.options.selectedIndex].value; self.location='bathmoi.php?cat=' + val ; }</script>
but my echoes still remains empty. i am confused. what shoul i do???
Last edited by dourvas; Sep 29th, 2009 at 4:05 am.
If I'm understanding correctly and you want to use a submit button, that is easy. For the code you are working with it would look something like As far $cat showing up in the URL, I would think that
echo '<input type="submit" name="button_name" id="button_id" value="Submit" />'; echo '</form>';
$_GET['cat']; should do what you want. I've used '@' to suppress errors before, but I never seen it used in front of a variable. Is there are a reason you are doing it that way? ![]() |
Similar Threads
- passing values of Select box from JSP to Action class thru form Bean (JSP)
- AJAX chained select (JavaScript / DHTML / AJAX)
- Nested Select Boxes in Javascript (JavaScript / DHTML / AJAX)
- Dynamic Select Boxes (JavaScript / DHTML / AJAX)
- Smart chained select boxes (JavaScript / DHTML / AJAX)
- How to pre-select checkboxes in form? (PHP)
Other Threads in the PHP Forum
- Previous Thread: Dehasher script malfunctioning
- Next Thread: What is $form<<<POST
| Thread Tools | Search this Thread |
apache api array beginner binary broken cache cakephp checkbox class cms code confirm cron curl customizableitems database date display dynamic echo email error external fcc file files folder form forms forum freelancing function functions google header headmethod howtowriteathesis href htaccess html iframe image include insert ip javascript joomla limit link login mail malfunction menu method mlm mod_rewrite multiple mysql neutrality oop pageing pagerank paypal pdf php phpmysql play problem query question radio random recursion remote root script search select server sessions sms soap source space sql support! syntax system table template tutorial update upload url validator variable video web youtube





