albertg Posted January 9, 2009 Share Posted January 9, 2009 I have been pulling my hair out trying to convert a piece of custom code a previous developer deployed. The developer created a custom multi-select drop-down that returns back a seperate list for each category it finds in the database. The client wanted to only display the first category in the database so I simply added a "break' to stop after displaying the first category. This was only a quick fix and since then I have been trying to get rid of the custom multi- select drop-down and replace it with just a simple drop-down that only allows the user one selection. I have tried numerous things but because the original code doesn't specify an actual value I cannot seem to get a single standard drop down created using the "break" to show only the first category from the database. Below is the snippet of original .thtml from the page. I have to leave the javascript as that is used to display what is selected in the drop down in another area of the page. Any help greatly appreciated: echo $form->create( 'Job', array( 'action' => 'index' ) )."\n"; echo "<div class=\"row\">"; echo '<h4 class="filter1">Select your function:</h4>'; foreach ($skillChapters as $skillChapter) break; { $currid = $skillChapter['SkillChapter']['id']; echo "<div class=\"selectSkillHm\">"; echo "<div class=\"floatLeft\" onclick=\"showHideFront('showchapter".$currid."','showRightMinus".$currid."','showRightPlus".$currid ."')\">".$skillChapter['SkillChapter']['title']."</div>"; echo "<div class=\"floatRight\" onclick=\"showHideFront('showchapter".$currid."','showRightMinus".$currid."','showRightPlus".$currid ."')\">"; echo "<span class=\"showElement\" id=\"showRightPlus".$currid."\">+</span><span class=\"hideElement\" id=\"showRightMinus".$currid."\">(Close)</span>"; echo "</div>"; // $skillCategories = $skillChapter['SkillCategory']; echo "<div class=\"hideSkillBox\" id=\"showchapter".$currid."\">"; $iteration =0; $skills = $skillChapter['Skill']; $skilIds = array(); foreach ($skills as $skill) { $skillid = $skill['id']; $skillIds[] = array("skill".$skill['id'],$skill['title'],$skillChapter['SkillChapter']['title']); echo "<div class=\"skillRow\">"; echo "<input type=\"checkbox\" name=\"data[Job][skill".$skillid."]\" value=\"1\" id=\"skill".$skillid."\">"; echo "<label for=\"skill".$skillid."\">{$skill['title']}</label>"; echo "</div>"; } echo "</div>"; echo "</div>"; } $iteration++; echo '<script type="text/javascript">'; echo 'var SKILLS = ['; for ($i=0; $i < count($skillIds); $i++) { echo '["'.$skillIds[$i][0].'","'.$skillIds[$i][1].'","'.$skillIds[$i][2].'"]'; if ($i < count($skillIds)-1) { echo ","; } } echo '];'; echo '</script>'; echo "</info></div>"; echo "<div id='selectedSkills' style='display:none;'></div>"; Quote Link to comment https://forums.phpfreaks.com/topic/140187-converting-custom-select-feature-to-drop-down/ Share on other sites More sharing options...
albertg Posted January 9, 2009 Author Share Posted January 9, 2009 Also, As a short term solution I was going to change the 'checkbox' to 'radio' to allow only one selection, but the radio buttons are still multi-selecting. If anyone can tell me what is causing this I could do a 'radio button' as a temporary fix if I cannot figure out a drop-down list. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/140187-converting-custom-select-feature-to-drop-down/#findComment-733699 Share on other sites More sharing options...
albertg Posted January 10, 2009 Author Share Posted January 10, 2009 Ok guys i know there is someone out there that can help me find out what i'm missing. I took the original code as listed above and I commented out the custom "drop-down" and added a standard drop down as listed in the code below. However, I cannot determine if the "$form->input" name is correct and I'm not sure why the drop-down selections are not choosing the right values to pass to the search function. Can anyone determine what I am missing based on what the original commented out code is? I did not comment out the second part of the original code because I'm thinking this is where the drop downs pass the values for the search function that is called. Any help greatly appreciated. Here is the modified code: echo $form->create( 'Job', array( 'action' => 'index' ) )."\n"; echo "<div class=\"row\">"; echo "<div class=\"floatThird\">"; echo "<div class=\"floatClear\">"; // echo "<label>Step 1: Select a Function</label>"; // foreach ($skillChapters as $skillChapter) // break; // { // $currid = $skillChapter['SkillChapter']['id']; // echo "<div class=\"selectSkillHm\">"; // echo "<div class=\"floatLeft\" onclick=\"showHideFront('showchapter".$currid."', 'showRightMinus".$currid."', 'showRightPlus".$currid."')\">".$skillChapter['SkillChapter']['title']."</div>"; // echo "<div class=\"floatRight\" onclick=\"showHideFront('showchapter".$currid."', 'showRightMinus".$currid."', 'showRightPlus".$currid."')\">"; // echo "<span class=\"showElement\" id=\"showRightPlus".$currid."\">+</span><span class=\"hideElement\" id=\"showRightMinus".$currid."\">(close)</span>"; // echo "</div>"; // // // echo "<div class=\"hideSkillBox\" id=\"showchapter".$currid."\">"; // $iteration =0; // $skills = $skillChapter['Skill']; // foreach ($skills as $skill) // { // $skillid = $skill['id']; // $skillIds[] = array("skill".$skill['id'],$skill['title'],$skillChapter['SkillChapter']['title']); // echo "<div class=\"skillRow\">"; // echo "<input type=\"checkbox\" name=\"data[Job][skill".$skillid."]\" value=\"1\" id=\"skill".$skillid."\"> "; // echo "<label for=\"skill".$skillid."\">{$skill['title']}</label>"; // echo "</div>"; // } // echo "</div>"; // $iteration++; // echo "</div>"; // } echo "<div class=\"floatClear\">"; echo $form->input( 'skills', array( 'label' => 'Step 1: Select a Function', 'type'=>'select', 'options'=> array( '' => 'Make a Selection', 'skill1' => 'Function 1', 'skill2' => 'Function 2', 'skill3' => 'Function 3', 'skill4' => 'Function 4', 'skill5' => 'Function 5', 'skill6' => 'Function 6', 'skill7' => 'Function 7', 'skill8' => 'Function 8', 'skill9' => 'Function 9' ) ) ); echo "</div>"; echo "<p class=\"error-message\">".$errormessage."</p>"; echo "</info>"; echo "</div>"; // echo '<script type="text/javascript">'; // echo 'var SKILLS = ['; // for ($i=0; $i < count($skillIds); $i++) { // echo '["'.$skillIds[$i][0].'","'.$skillIds[$i][1].'","'.$skillIds[$i][2].'"]'; // if ($i < count($skillIds)-1) { // echo ","; // } // } // echo '];'; // echo '</script>'; echo "<div id='selectedSkills' style='display:none;'></div>"; echo "<div class=\"floatClear\">"; echo "<div id=\"skillsbox\" class=\"hideElement\">"; echo "<div class=\"floatLeft\">"; $curr = 0; foreach ( $skillsArr as $index => $skill ) { if ($curr % $percols == 0) { echo "</div><div class=\"floatLeft\">"; } echo "<div class=\"checkbox\"><input type=\"checkbox\" name=\"data[Job][skill".$index."]\" value=\"1\" id=\"Job".$skill."\"> ".$skill."</div>"; $curr++; } echo "</div>"; echo "</div>"; echo "</div>"; echo "</div>"; Quote Link to comment https://forums.phpfreaks.com/topic/140187-converting-custom-select-feature-to-drop-down/#findComment-734041 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.