Jump to content



Photo
php drop-down checkboxes

  • Please log in to reply
1 reply to this topic

#1 pthornton

pthornton

    Resident One Post Wonder

  • Joined: 10-July 13

Posted 11 July 2013 - 18:31

I'm modifying a form and is something I've never actually had the experience in working with. For the record I don't code PHP.

In short: the html/php form has a drop down of five values (5 fields of research) of which you can only select one. But the client would like to be able to select more than one. So now I would like to trash the drop down and have checkboxes instead.

I would prefer to do the least mods to what is currently set-up.

Note* This is a dynamic dropdown list; so the values are pulled from another table and submitted to the database.

Here's the code I'm working with:

 

$query_fields_of_research = "SELECT * FROM tblOpportunityFieldOfResearch ORDER BY field_of_research_en ASC;";
$sql->query($query_fields_of_research, SQL_ALL, SQL_ASSOC);
$fields_of_research = $sql->record;
?>

<select name="strFieldOfStudy_en" id="strFieldOfStudy_en">
 

<?php
foreach ($fields_of_research as $field) {

$selectedValue= "";
if ($strFieldOfStudy_en == $field['id'])

$selectedValue= " selected";

echo "\t\t\t".'<option value="'.$field['id'].'"'.$selectedValue.'>'.$field['field_of_research_en']." </option>\n";

}

?>

</select>

 

Following this, the submitted data is also updated to a webpage in a table with this:

 

<tr>

<td>Fields of research</td>

<td>

 

<?php
$fieldsOfResearch
= array('1', '2', '3', '4', '5');
if (in_array($opp['strfieldofstudy_en'], $fieldsOfResearch)){

echo $iri->getFieldOfResearch($opp['strfieldofstudy_en'], 'en');

}

else

echo $opp['strfieldofstudy_en'];

?>

 

</td>

</tr>

 

How would I change the dropdown to checkboxes with the least amount of mods?




#2 SPEhosting

SPEhosting

    C++ n00b

  • Tech Issues Solved: 1
  • Joined: 15-July 08
  • Location: my room
  • OS: windows 7, backtrack 5, OSx 10.6

Posted 25 July 2013 - 04:04

 

I'm modifying a form and is something I've never actually had the experience in working with. For the record I don't code PHP.

In short: the html/php form has a drop down of five values (5 fields of research) of which you can only select one. But the client would like to be able to select more than one. So now I would like to trash the drop down and have checkboxes instead.

I would prefer to do the least mods to what is currently set-up.

Note* This is a dynamic dropdown list; so the values are pulled from another table and submitted to the database.

Here's the code I'm working with:

 

$query_fields_of_research = "SELECT * FROM tblOpportunityFieldOfResearch ORDER BY field_of_research_en ASC;";
$sql->query($query_fields_of_research, SQL_ALL, SQL_ASSOC);
$fields_of_research = $sql->record;
?>

<form name="NAME" action="URL" method="POST">
 

<?php
foreach ($fields_of_research as $field) {

$selectedValue= "";
if ($strFieldOfStudy_en == $field['id'])

$selectedValue= " selected";

echo "\t\t\t".'<input type='checkbox'  value="'.$field['id'].'"'.$selectedValue.' name='strFieldOfStudy_en' id='strFieldOfStudy_en'>'.$field['field_of_research_en']." </option>\n";

}

?>

</form>

 

 

 

 

 

that should do ya /\ or something like that atleast best i can do at 5 am ;D lol (sorry if i messed up the speech marks, wasnt really paying 100% attention to detail not going to lie)





Click here to login or here to register to remove this ad, it's free!