denzlite Posted May 13, 2009 Share Posted May 13, 2009 This is my secretary's problem: A coder before I cam built her a form where she can enter information for multiple patients at once. So there's a form with two columns of dropdown menus: one for patient_type and one for patient_scale. All the types and scales are drawn from db. What she would like to be able to do is every time she selects a type in one column - the menu in the corresponding column updates with some scale info placed in the create portion of the db // BUT she'd also like to be able to still select a different scale if necessary. Now I've seen pages with ajax where one drop down say country that updates another dropdown/cities - but if you've got 14 or so rows of linked menus - well my php is pretty beginner so I'd thought I'd post this here after much searching. Any help appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/157897-multiple-dynamic-dropdowns/ Share on other sites More sharing options...
Ken2k7 Posted May 13, 2009 Share Posted May 13, 2009 So the coder before you built this up to where? Are you starting over? What part is left undone? What do you have to code? By the way, you can request stuff in the Freelance forum. *Most* people require payment though. However, you're not allowed to request stuff outside that forum. Quote Link to comment https://forums.phpfreaks.com/topic/157897-multiple-dynamic-dropdowns/#findComment-832988 Share on other sites More sharing options...
denzlite Posted May 13, 2009 Author Share Posted May 13, 2009 He built it to the point where there are 2 columns/14 rows of linked dropdowns that submit to db. I think I can handle the submission part - I'm wondering how you have more than two ajax enabled/dynamically updating/linked - oh I don't know how to begin searching for a solution. Am I even using the right terminology? Like I said, I've searched high and low and only found tutorials/suggestions/code for two to three dynamically linked dropdowns. Paying is not an option, if all else fails - she uses the old code. I just wanted to help her out and pick up some ajax at the same time. I'm also not a coder. I know a little about PHP/MySQL - so if someone could point me to good example of more than one set of linked dropdowns using ajax I was thinking I would jimmy around with it a little and see if I couldn't get it to work. Quote Link to comment https://forums.phpfreaks.com/topic/157897-multiple-dynamic-dropdowns/#findComment-833280 Share on other sites More sharing options...
Ken2k7 Posted May 13, 2009 Share Posted May 13, 2009 Well this will be AJAX and SQL heavy. I would just end up adding a new AJAX call per dropdown, sending over data to a PHP file which will have to do a heck load of parsing to output the contents to display next. It's not hard, but it's not something that would be done right away because there's a lot to it. Quote Link to comment https://forums.phpfreaks.com/topic/157897-multiple-dynamic-dropdowns/#findComment-833288 Share on other sites More sharing options...
denzlite Posted May 13, 2009 Author Share Posted May 13, 2009 Here is code - remember - three or four brains have had their way with this (sorry posted this before I read your reply) <?php require_once('Connections/connAdmin.php'); ?> <?php require_once('includes/functions.php'); ?> <?php $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { // Initialize array for error messages $error = array(); // Remove whitespace and check first and family names $_POST['payperiodname'] = trim($_POST['payperiodname']); $_POST['payperiod'] = trim($_POST['payperiod']); if (empty($_POST['payperiod']) || empty($_POST['payperiodname'])) { $error['name'] = 'Please enter both first name and last name'; } if (!$error) { $insertSQL = sprintf("INSERT INTO tbl_payroll_wksht (id, payperiodname, payperiod) VALUES (%s, %s, %s)", GetSQLValueString($_POST['payperiodnname'], "text"), GetSQLValueString($_POST['payperiod'], "text")); $Result1 = mysql_query($insertSQL, $connAdmin); if (!$Result1 && mysql_errno() == 1062) { $error['payperiod'] = $_POST['payperiod'] . ' is already in use. Please choose a different username.'; } elseif (mysql_error()) { $error['dbError'] = mysql_error(); } else { /* $insertGoTo = "payroll.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo));*/ $submittime = date("F j, Y, g:i a"); ////////////////////////////////////////////////////////////////////////////////////////////////// $query2 = "SELECT * FROM tbl_payroll_wksht WHERE name = '$payperiodname' and date = '$payperiod'"; $result = mysql_query($query2) or die ("&Status=Error in query: $query. " .mysql_error()); $row = mysql_fetch_object($result); $wksht_id = $row->wksht_id; ///////////////////////////////////////////////////////////////////////////////////////////////////// for($i=0;$i < 35;$i++) { $hours = "hrs".$i; $$hours = $_POST[$hours]; $hours2 = $$hours; $notes = "notes".$i; $$notes = $_POST[$notes]; $notes2 = $$notes; $date = "date".$i; $$date = $_POST[$date]; $date2 = $$date; //echo "hours=".$$hours."<br>"; $sp = "sp".$i; $$sp = $_POST[$sp]; $sp2 = $$sp; //echo "sp=".$$sp."<br>"; $pt = "pt".$i; $$pt = $_POST[$pt]; $pt2 = $$pt; //echo "pt=".$$pt."<br>"; if ($$hours != "" || $$hours != NULL){ $Query="INSERT INTO tbl_payroll VALUES('$id', '$wksht_id', '$sp2', '$hours2', '$pt2', '$date2', '$notes2')"; mysql_query($Query, $dbh) or die ("Didn't Query"."<br>".mysql_error()); } } } } } ?> <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1"> <table width=60%><tr> <?php if (isset($error)) { echo '<ul>'; foreach ($error as $alert) { echo "<li class='warning'>$alert</li>\n"; } echo '</ul>'; // remove escape characters from POST array if (PHP_VERSION < 6 && get_magic_quotes_gpc()) { function stripslashes_deep($value) { $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); return $value; } $_POST = array_map('stripslashes_deep', $_POST); } } ?> <td>Enter Pay Period Name: <i>(Required) </i><input size=25 type="text" name="payperiodname" value="<?php if (isset($_POST['payperiodname'])) {echo htmlentities($_POST['sp_first_name'], ENT_COMPAT, 'UTF-8');} ?>" /></td> </tr></table> <hr> <table width=82%><tr> <td>Enter Pay Period: <i>(Required) </i><input size=15 type="text" name="payperiod" value="<?php if (isset($_POST['payperiod'])) {echo htmlentities($_POST['payperiod'], ENT_COMPAT, 'UTF-8');} ?>" /> <INPUT TYPE="button" VALUE="Calendar" onClick="cal1.select(document.forms[\'form2\'].payperiod,\'anchor1\',\'yyyy-MM-dd\'); return false;" TITLE="cal1.select(document.forms[\'form2\'].payperiod,\'anchor1\',\'yyyy-MM-dd\'); return false;" NAME="anchor1" ID="anchor1"></td> <td><INPUT TYPE="button" VALUE="Add to Date Field below" onClick="fillinDate()"></td> </tr></table> <hr> <table width=100%><tr> <td width=30%>Name:</td> <td width=35%><a href="javascript:void(0)" onclick="changePR()">Rate:</a></td> <td width=13%>Date:</td> <td width=7%>Hours:</td> <td width=15%>Notes:</td> </tr> <?php //this is if training is being filled out//////////////////////////////// for($i=0;$i < 35;$i++) { if ($i % 2 == 0){ echo '<tr bgcolor="#CCCCCC">'; }else{ echo '<tr bgcolor="#e9e9f8">'; } if ($i < 9){ echo '<td>'.($i+1).". ".' '.'<select name="sp'.$i.'">'; }else{ echo '<td>'.($i+1).". ".'<select name="sp'.$i.'">'; } $sql5="Select sp_id, sp_last_name,sp_first_name from tbl_sps where sp_id > 0 Order by sp_last_name,sp_first_name"; $result5=mysql_query($sql5); while($row5=mysql_fetch_array($result5)) { echo '<option value="'.$row5['sp_id'].'">'.$row5['sp_last_name'].', '.$row5['sp_first_name'].'</option>'; } echo '</select></td>'; echo '<td><select name="pt'.$i.'">'; $sql6="Select sppt_id, payroll_type_name from tbl_sp_payroll_types where sppt_id > 0 order by payroll_type_name"; $result6=mysql_query($sql6); while($row6=mysql_fetch_array($result6)) { $ptcheck = $row6['sppt_id']; if ($ptcheck == $payrate){ echo '<option value="'.$row6['sppt_id'].'" selected="selected">'.$row6['payroll_type_name'].'</option>'; }else{ echo '<option value="'.$row6['sppt_id'].'">'.$row6['payroll_type_name'].'</option>'; } } echo '</select></td>'; echo '<td><input size=9 type="text" name="date'.$i.'" value='.$payperiod.'>'; //echo '<option value="'.$payperiod.'">'.$payperiod.'</option>'; //echo '</td>'; echo '<td><input size=4 type="text" name="hrs'.$i.'"></td>'; echo '<td><textarea name="notes'.$i.'" id="notes'.$i.'" cols="20" rows="2"></textarea></tr>'; } echo '<td><input type="submit" value="Insert record" /></td> <input type="hidden" name="MM_insert" value="form1" /> </form>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/157897-multiple-dynamic-dropdowns/#findComment-833290 Share on other sites More sharing options...
Ken2k7 Posted May 13, 2009 Share Posted May 13, 2009 What do you want me to do with that? Quote Link to comment https://forums.phpfreaks.com/topic/157897-multiple-dynamic-dropdowns/#findComment-833292 Share on other sites More sharing options...
denzlite Posted May 13, 2009 Author Share Posted May 13, 2009 there's a lot to it I'm wondering if there's a different solution other than Ajax? Quote Link to comment https://forums.phpfreaks.com/topic/157897-multiple-dynamic-dropdowns/#findComment-833296 Share on other sites More sharing options...
JonnoTheDev Posted May 13, 2009 Share Posted May 13, 2009 I'm wondering if there's a different solution other than Ajax? Not unless you want to keep having to submit the form every time an item is selected from a list. Remember PHP is server side. Data must be sent to the server before it can be processed (i.e. submit the form). This is where AJAX comes in. You can run server side scripts without the need to submit and reload the page, obtain data and change page elements based on user actions / selections. Here is a simple tutorial to get you going: http://www.tizag.com/ajaxTutorial/ajax-mysql-database.php If I were you I would look into recreating the system in your own fashion if you cannot add to the existing codebase. Quote Link to comment https://forums.phpfreaks.com/topic/157897-multiple-dynamic-dropdowns/#findComment-833315 Share on other sites More sharing options...
Ken2k7 Posted May 13, 2009 Share Posted May 13, 2009 People rely on Dreamweaver way too much. Quote Link to comment https://forums.phpfreaks.com/topic/157897-multiple-dynamic-dropdowns/#findComment-833325 Share on other sites More sharing options...
denzlite Posted May 13, 2009 Author Share Posted May 13, 2009 Thanks, yes I did take that tutorial, so I am semi familiar with how simple Ajax can update a MySQL db... Yes, there's a little DW code in there - ;( but i'm not relying on DW... Basically what I do is go out and get code from books and what not and then figure out how to make it work for what I want to do... so if I could somehow see good working Ajax code for dynamic linked dropdown that'd be cool... a lot of sites have the city/country example... Quote Link to comment https://forums.phpfreaks.com/topic/157897-multiple-dynamic-dropdowns/#findComment-833394 Share on other sites More sharing options...
Ken2k7 Posted May 13, 2009 Share Posted May 13, 2009 a lot of sites have the city/country example... You can go to those sites and view their source code for the JavaScript. Quote Link to comment https://forums.phpfreaks.com/topic/157897-multiple-dynamic-dropdowns/#findComment-833406 Share on other sites More sharing options...
denzlite Posted May 13, 2009 Author Share Posted May 13, 2009 Does anyone have any different code than those examples? http://www.google.com/search?hl=en&q=ajax+dependent+lists Sorry, the URL above - Is this the proper terminolgoY? Quote Link to comment https://forums.phpfreaks.com/topic/157897-multiple-dynamic-dropdowns/#findComment-833463 Share on other sites More sharing options...
Ken2k7 Posted May 13, 2009 Share Posted May 13, 2009 What's the URL for? Quote Link to comment https://forums.phpfreaks.com/topic/157897-multiple-dynamic-dropdowns/#findComment-833467 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.