/    Sign up×
Community /Pin to ProfileBookmark

Converting custom select feature to drop-down

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 .html 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>”;

to post a comment
HTML

2 Comments(s)

Copy linkTweet thisAlerts:
@ag3451authorJan 09.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!
Copy linkTweet thisAlerts:
@ag3451authorJan 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&nbsp;1:&nbsp;Select&nbsp;a&nbsp;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 &#37; $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>";
×

Success!

Help @ag3451 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.14,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...