swatisonee Posted June 1, 2010 Share Posted June 1, 2010 Am having problems with incorporating a multiple dropdown in my form. The dropdown works in a fashion. But I cannot submit the data in fields other than the dropdown to a new new form / script . The select on change accesses form2.php instead of calling itself. Am going in circles trying to sort it all out. Have stripped the foll. script of much of the html code so would appreciate inputs . Thanks. <? header("Cache-Control: public"); include ("../logindl.php"); //db info for DB2 if(!isset($_SESSION['userid'])) { echo "<center><font face='Calibri' size='2' color=red>Sorry, Please login and use this page </font></center>"; exit;} $userid = $_SESSION['userid']; ?> <html> <head> //title etc </head> <body lang=EN-IN> <div class=Section1> <form method="post" action="form2.php?userid=<? echo $userid ?>"> // this script takes in all the data selected on the whole form and then processes it <script type="text/javascript" src="../datepicker/datetimepicker_css.js"></script> <p class=MsoNormal align=right style='text-align:right'><b><span lang=EN-US style='font-size:12.0pt;color:#000058'> </span></b></p> <p class=MsoNormal><b><span lang=EN-US style='font-size:12.0pt;color:#000058'> </span></b></p> <td>UID:<input type=hidden name="uid" size=8 value="<? echo $userid ?>"> <input type=text name="uid" size=8 value="<? echo $userid ?>" disabled="true"></a></td> <td>Date:<input type=text name="meetdate" size=12> <a href="javascript:NewCssCal('meetdate', 'yyyymmdd')"> <img src="../datepicker/images/cal.gif" width="16" height="16" alt="Pick a date"></a></td> <td>Company: //processing data recd. from the select onchange <?php $cid = $_POST['cid']; $sql = "SELECT * FROM Customers c INNER JOIN Custaddress a USING(CID) INNER JOIN Custcontact t USING(CAID) WHERE c.CID = '$cid' ORDER BY Company asc"; $result = mysql_query($sql) or die (mysql_error ()); if ($myrow = mysql_fetch_array($result)) { do { $cityid= $myrow['CITYID']; $sql3 =" SELECT * FROM Cities WHERE CITYID = $cityid "; $result3 = mysql_query( $sql3 ) or die (mysql_error()); $myrow3 = mysql_fetch_array($result3); $city = $myrow3['City']; ?> <td>Select</td> <td>City</td> <td>Name</td> </tr> <? printf("<td><input type=\"radio\" name=\"choice\" value=%d></td> <td>%s</td> <td>%s</td></tr></table>", $myrow["CID"], $city, $myrow["Firstname"]." ".$myrow["Lastname"] ); } while ($myrow = mysql_fetch_array($result)); } ?> //getting the form to call itself. once customer is selected, it shud call itself and offer an address and contact to be selected <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post"> <select name="cid" onchange="this.form.submit()"> <?php $resulta = mysql_query("SELECT * FROM `Customers` ORDER BY `Company` asc "); if ($myrowa = mysql_fetch_array($resulta)) { do { printf("<option value=%s> %s", $myrowa["CID"], $myrowa["Company"]); } while ($myrowa = mysql_fetch_array($resulta)); echo "</select>\n"; } ?></a> </span></b></p></form> </td> </tr> Interaction By:<select name="meetby"> <option value=""> <option value="M">Meeting <option value="T">Telephone </select></a> </td> <td>Vendor:<select name="vid"></span><span lang=EN-US style='font-size:12.0pt;color:#333333'> </span> <?php $resultb = mysql_query("SELECT * FROM `Vendors` ORDER BY `Name` asc "); if ($myrowb = mysql_fetch_array($resultb)) { do { printf("<option> %s", $myrowb["Name"]); } while ($myrowb = mysql_fetch_array($resultb)); echo "</select>\n"; } else { echo "Sorry, no records were found!"; echo "</select>\n"; } ?></a></td> </tr> <p align="center"><b><span style='font-size:10.0pt;color:#000058'>Upload Report Here: <input type="radio" checked name="report" value="1"></a> OR <input type="radio" checked name="report" value="0"></a>:Type Report Below </td> </tr> <? include ("phUploader.php"); ?> <textarea name ="disc1" rows="10" cols="75"></textarea></a> </td> </tr> <td> FILE <input type="radio" checked name="fileit" value="1"></a> OR <input type="radio" checked name="fileit" value="0"></a> :EMAIL </span></b> <input name='submit' type='submit' value='SUBMIT IT !'></a> </td> </tr> </form> </table> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/203530-the-trouble-with-trying-to-simplify-dropdowns/ Share on other sites More sharing options...
riwan Posted June 1, 2010 Share Posted June 1, 2010 you're not permitted to use form inside form must be like this : <form... > </form> <form... > </form> Quote Link to comment https://forums.phpfreaks.com/topic/203530-the-trouble-with-trying-to-simplify-dropdowns/#findComment-1066185 Share on other sites More sharing options...
swatisonee Posted June 2, 2010 Author Share Posted June 2, 2010 oh dear ! so how do i then pass the variables from the rest of the script apart from the subform ? Quote Link to comment https://forums.phpfreaks.com/topic/203530-the-trouble-with-trying-to-simplify-dropdowns/#findComment-1066454 Share on other sites More sharing options...
greatstar00 Posted June 2, 2010 Share Posted June 2, 2010 below for client side programming in the subform, <form onclick="return returnvalue()" name="form1" /> function returnvalue(){ document.form2.hiddenfield.value = document.form1.field.value; return false; } in your inner (actually, the 1st form), use javascript to pass the value to the 2nd form(outer form) hidden field below for server side programming create 2 pages, 1st page contain the inner form only submit to 1st page, then on this 1st page, write the 2nd form, include 1st's form value as hidden field <input type="hidden" name="1stformname1" value="<?php echo $_POST[1stformname1] ?>" /> Quote Link to comment https://forums.phpfreaks.com/topic/203530-the-trouble-with-trying-to-simplify-dropdowns/#findComment-1066467 Share on other sites More sharing options...
swatisonee Posted June 2, 2010 Author Share Posted June 2, 2010 thanks. that means my user will see 2 pages right ? The first where they choose customer , the form calls itself and then they choose contact, address. then i have to create a 2nd html page where the other data can be filled in and the variables from the first page get passed on - that means i cannot use the "multiple dropdown" method , right? Quote Link to comment https://forums.phpfreaks.com/topic/203530-the-trouble-with-trying-to-simplify-dropdowns/#findComment-1066483 Share on other sites More sharing options...
riwan Posted June 2, 2010 Share Posted June 2, 2010 in 1 page only <form... > </form> <form... > </form> for the first form your action should be your intended submit page for the second form your action should be the page itself but contain only hidden value your user would not see the second form. Then onchange fill in your second form and then submit the second form Quote Link to comment https://forums.phpfreaks.com/topic/203530-the-trouble-with-trying-to-simplify-dropdowns/#findComment-1066486 Share on other sites More sharing options...
swatisonee Posted June 2, 2010 Author Share Posted June 2, 2010 I have got this down from a code i saw elsewhere. Now the problem is that when the "onchange" doesnt work. That is when the user selects a company, the form doesnt call itself. I feel i'm getting into a black hole here ! Would appreciate if someone could change/ add what i seem to be missing. <? header("Cache-Control: public"); include ("../logindl.php"); //db info for DB2 if(!isset($_SESSION['userid'])) { echo "<center><font face='Calibri' size='2' color=red>Sorry, Please login and use this page </font></center>"; exit;} $userid = $_SESSION['userid']; ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <SCRIPT language=JavaScript> function reload(form) { var val=form.cat.options[form.cat.options.selectedIndex].value; self.location="view_enqs.php?userid=<? echo $userid ?>&cat=" + val ; } </script> </head> <table border="1" width="50%" align="center"> <td colspan="2" width="35%"> <? ///////// Getting the data from Mysql table for first list box////////// $sqla = "SELECT * FROM `Customers` ORDER BY `Company` asc"; echo $sqla; $resulta=mysql_query($sqla) or die (mysql_error()); if(isset($_GET['cat'])) { $cat=$_GET['cat']; } echo $cat; if(isset($cat) and strlen($cat) > 0){ $sqlb = "SELECT `CITYID` FROM `Custaddress` WHERE `CID`= $cat ORDER BY `CITYID` asc"; echo $sqlb; $resultb=mysql_query($sqlb) or die (mysql_error()); $sqlc = "SELECT `Lastname` FROM `Custcontact` WHERE `CID`= $cat ORDER BY `Lastname` asc"; echo $sqlb; $resultc=mysql_query($sqlc) or die (mysql_error()); } else{ $resultb=mysql_query("SELECT `CITYID` FROM `Custaddress ORDER BY `CITYID` asc"); $resultc=mysql_query("SELECT `Lastname` FROM `Custcontact` ORDER BY `Lastname` asc"); } echo "<form method=post action='view_enqs2.php?userid=<? echo $userid ?>&cat=<? echo $cat?>'>"; // the 2nd form echo '<input name="cat" type="hidden" value="cat">'; echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>"; while($myrowa = mysql_fetch_array($resulta)) { if($myrowa['CID']==@$cat) { echo "<option selected value='$myrowa[CID]'>$myrowa[Company]</option>"."<BR>";} else {echo "<option value='$myrowa[CID]'>$myrowa[Company]</option>";} } echo "</select>"; ?></td> <tr> <td> <? echo "<select name='adrs'><option value=''>Select one</option>"; while($myrowb = mysql_fetch_array($resultb)) { echo "<option value='$myrowb[CITYID]'>$myrowb[CITYID]</option>"; } echo "</select>"; ?> </td> <td><? echo "<select name='ln'><option value=''>Select one</option>"; while($myrowc = mysql_fetch_array($resultc)) { echo "<option value='$myrowc[Lastname]'>$myrowc[Lastname]</option>"; } echo "</select>"; ?> <td></td> <td></td> </tr> </table> </div> <p><p> <table border="1" width="50%" align="center"> <tr> <td align="center" width="20%"><font color="#3366FF" face="Tahoma" size="2"><strong>Offer No.</td> <td align="center" width="20%"><font color="#3366FF" face="Tahoma" size="2"><strong>Offer Date</td> </tr> <tr> <td width="20%"><input type="text" name="off_number" size="20"></td> <td width="20%"><input type="text" size="20" name="off_date"></td> </tr> </table> </div> <p> <p> <table border="1" cellspacing="1" width="100%" bgcolor="#0000FF"> <tr> <td width="50%" bgcolor="#3366FF"><p align="center"><font color="#FFFFFF" size="2" face="Tahoma">Please click this button just once to avoid any errors. <input type="submit" value="Submit"></font></p> </td> </tr> </table> <input type="hidden" name="cid" value="<? echo $cid ?>"> <input type="hidden" name="userid" value="<? echo $userid ?>"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/203530-the-trouble-with-trying-to-simplify-dropdowns/#findComment-1066496 Share on other sites More sharing options...
swatisonee Posted June 2, 2010 Author Share Posted June 2, 2010 Am bereft of ideas now ! i got this code from plus2net.com so while the dropdown gets selected , no amount of clicking on the submit button at the end of the main form helps. the form view_enqs1.php just doesnt get loaded ! What am i doing wrong pl ! <? header("Cache-Control: public"); include ("../logindl.php"); //db info for DB2 if(!isset($_SESSION['userid'])) { echo "<center><font face='Calibri' size='2' color=red>Sorry, Please login and use this page </font></center>"; exit;} $userid = $_SESSION['userid']; ?> <html> <head> <SCRIPT language=JavaScript> function reload(form) { var val=form.cat.options[form.cat.options.selectedIndex].value; self.location='view_enqs.php?cat=' + val ; } </script> </head> <? @$cat=$_GET['cat']; $quer2=mysql_query("SELECT DISTINCT `Company`,`CID` FROM `Customers` ORDER BY `Company` asc "); if(isset($cat) and strlen($cat) > 0){ $quer=mysql_query("SELECT DISTINCT `CITYID` FROM `Custaddress` WHERE `CID`= $cat ORDER BY `CITYID` asc"); $quer3=mysql_query("SELECT `Lastname` FROM `Custcontact` WHERE `CID`= $cat ORDER BY `Lastname` asc"); }else{$quer=mysql_query("SELECT DISTINCT `CITYID` FROM `Custaddress ORDER BY `CITYID` asc"); $quer3=mysql_query("SELECT `Lastname` FROM `Custcontact` ORDER BY `Lastname` asc"); } echo "<form method=post action='view_enqs1.php?userid=<? echo $userid ?>&cat=<? echo $cat?>'>"; //THIS IS THE MAIN FORM echo '<input name="cat" type="hidden" value="cat">'; echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>"; while($noticia2 = mysql_fetch_array($quer2)) { if($noticia2['CID']==@$cat){echo "<option selected value='$noticia2[CID]'>$noticia2[Company]</option>"."<BR>";} else{echo "<option value='$noticia2[CID]'>$noticia2[Company]</option>";} } echo "</select>"; echo "<select name='subcat'><option value=''>Select one</option>"; while($noticia = mysql_fetch_array($quer)) { echo "<option value='$noticia[CITYID]'>$noticia[CITYID]</option>"; } echo "</select>"; echo "<select name='subcat2'><option value=''>Select one</option>"; while($noticia3 = mysql_fetch_array($quer3)) { echo "<option value='$noticia3[Lastname]'>$noticia3[Lastname]</option>"; } echo "</select>"; ?> Type:<select name="meettype"> <option value="">[select One] <option value="Preop">Preop <option value="Postop">Postop <option value="Postorder">Postorder </select></a></span></b></p> </td> <p class=MsoNormal align=center style='text-align:center'><b><span style='font-size:10.0pt;color:#000058'> FILE IT:<input type="radio" checked name="fileit" value="1"></a></span></b><b><span style='font-size:10.0pt;color:#000058'> or EMAIL IT !<input type="radio" checked name="fileit" value="0"></a> SUbmit <input type="submit" value="Submit"></font></p> </td> </tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/203530-the-trouble-with-trying-to-simplify-dropdowns/#findComment-1066528 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.