iam using codeigniter
<select id="example-label" multiple="multiple">
<option value="option-1">Option 1</option>
<option value="option-2">Option 2</option>
<option value="option-3">Option 3</option>
<option value="option-4">Option 4</option>
<option value="option-5">Option 5</option>
<option value="option-6">Option 6</option>
</select>`
how to insert multi-select value
<select id="example-label" multiple="multiple" name='youroption[]'>
<option value="option-1">Option 1</option>
<option value="option-2">Option 2</option>
<option value="option-3">Option 3</option>
<option value="option-4">Option 4</option>
<option value="option-5">Option 5</option>
<option value="option-6">Option 6</option>
</select>
Add This in Your Contoller
<?php
function get_data()
{
$optiondata=$this->input->post('youroption');
var_dump($optiondata);
}
?>
or extract using loop
foreach($optiondata as $key=>$value)
{
echo $value;
}
Related
I have a multiple=multiple drop down list and I want to check if a user has selected any option or not using PHP code. If not, then I want to display an error message. How can I do that?
<select name="ddlskill" multiple="multiple">
<option value="Cake PHP">Cake PHP</option>
<option value="Database">Database</option>
<option value="hello">hello</option>
<option value="Java">Java</option>
<option value="Jquery">Jquery</option>
<option value="JSON">JSON</option>
<option value="JSP">JSP</option>
<option value="Mysql">Mysql</option>
<option value="PHP">PHP</option>
<option value="xyz">xyz</option>
<option value="XYZ2">XYZ2</option>
</select>
You should declare your html like this :
<select name="ddlskill[]" multiple="multiple">
<option value="Cake PHP">Cake PHP</option>
<option value="Database">Database</option>
<option value="hello">hello</option>
<option value="Java">Java</option>
<option value="Jquery">Jquery</option>
<option value="JSON">JSON</option>
<option value="JSP">JSP</option>
<option value="Mysql">Mysql</option>
<option value="PHP">PHP</option>
<option value="xyz">xyz</option>
<option value="XYZ2">XYZ2</option>
</select>
And then in PHP, you'll get an array of values :
if( !empty($_POST['ddlskill']) ){
print_r($_POST['ddlskill']);
// [PHP, JSP, Java, ...]
}
Maybe helpful,
<?php
if( isset($_POST) && !empty($_POST['ddlskill'])){
echo "<pre>";print_r($_POST['ddlskill']);
// [PHP, JSP, Java, ...]
}
?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" method="post">
<select name="ddlskill[]" multiple="multiple">
<option value="Cake PHP">Cake PHP</option>
<option value="Database">Database</option>
<option value="hello">hello</option>
<option value="Java">Java</option>
<option value="Jquery">Jquery</option>
<option value="JSON">JSON</option>
<option value="JSP">JSP</option>
<option value="Mysql">Mysql</option>
<option value="PHP">PHP</option>
<option value="xyz">xyz</option>
<option value="XYZ2">XYZ2</option>
</select>
<button type="submit"> Submit </button>
</form>
<?php
if(!empty($_POST['submit'])){
if(is_array($_POST['ddlskill']))
{
foreach($_POST['ddlskill'] as $key=>$value)
{
print_r($value);
}
}
else
{
print_r($_POST['ddlskill']);
}
}
?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" method="post">
<select name="ddlskill[]" multiple="multiple">
<option value="Cake PHP">Cake PHP</option>
<option value="Database">Database</option>
<option value="hello">hello</option>
<option value="Java">Java</option>
<option value="Jquery">Jquery</option>
<option value="JSON">JSON</option>
<option value="JSP">JSP</option>
<option value="Mysql">Mysql</option>
<option value="PHP">PHP</option>
<option value="xyz">xyz</option>
<option value="XYZ2">XYZ2</option>
</select>
<button type="submit" name="submit"> Submit </button>
</form>
This question already has answers here:
How can I set the default value for an HTML <select> element?
(34 answers)
Closed 6 years ago.
When will I update my semester that time by default a checkbox to be checked how it possible ?
<select name="semester">
<option value="">Select Semester</option>
<option value="1">Semester 1</option>
<option value="2">Semester 2</option>
<option value="3">Semester 3</option>
</select>
You can use the selected attribute.
<select name="semester">
<option value="">Select Semester</option>
<option value="1" selected="selected">Semester 1</option>
<option value="2">Semester 2</option>
<option value="3">Semester 3</option>
</select>
Please try this
<select name="semester">
<option value="">Select Semester</option>
<option value="1" <?php if($data['semester']==1){echo 'selected';}?>>Semester 1</option>
<option value="2" <?php if($data['semester']==2){echo 'selected';}?>>Semester 2</option>
<option value="3" <?php if($data['semester']==3){echo 'selected';}?>>Semester 3</option>
</select>
If you want to select semester 2 so here you go:
HTML:
<select name="semester">
<option value="">Select Semester</option>
<option value="1">Semester 1</option>
<option value="2" selected>Semester 2</option>
<option value="3">Semester 3</option>
</select>
Jquery:
$("select option").each(function(){
if ($(this).text() == "Semester 2")
$(this).attr("selected","selected");
});
yes,it possible. you have to use selected in <option>
<select name="semester">
<option value="">Select Semester</option>
<option value="1" selected>Semester 1</option>
<option value="2">Semester 2</option>
<option value="3">Semester 3</option>
</select>
DEMO
<option value="1" <?= ($value=='1')?'selected':"" ?>>Semester 1</option>
<option value="2" <?= ($value=='2')?'selected':"" ?>>Semester 2</option>
<option value="3" <?= ($value=='3')?'selected':"" ?>>Semester 3</option>
you can get the value form database or session,
We really need your specific PHP code to help, but perhaps this generic example will show you how to do this when you have your data and your desired value:
<?php
//Your array of data
$myData = array(
'1' => 'Semester 1',
'2' => 'Semester 2',
'3' => 'Semester 3');
//The value you want to be selected
$myValue = "2";
?>
<select name="semester">
<option value="">Select Semester</option>
<?php
foreach($myData as $key => $value){
echo ('<option value="'.$key.'"' );
if( $myValue == $key){
echo( ' selected="selected" ');
}
echo ('>'.$value.'</option');
echo "\n";
}
?>
</select>
This is what I got so far, it's just the dropdown list. It's a form for making a reservation for appointment. I want to print out these selected values (= selected options of dropdown)
But I have no clue since I'm very new with PHP and HTML. Something with $_POST and $_GET ? Could I have some suggestions of solution? Much gratitude.
<html>
<head>
<title>title</title>
</head>
<body>
<select name="Ar" id="Ar">
<option value="1">2014</option>
<option value="2">2015</option>
<option value="3">2016</option>
<option value="4">2017</option>
<option value="5">2018</option>
<option value="6">2019</option>
</select>
<select name="Manad" id="Manad">
<option value="1">Januari</option>
<option value="2">Februari</option>
<option value="3">Mars</option>
<option value="4">April</option>
<option value="5">Maj</option>
<option value="6">Juni</option>
<option value="7">July</option>
<option value="8">Augusti</option>
<option value="9">September</option>
<option value="10">Oktober</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="Dag" id="Dag">
<option value="1">Mandag</option>
<option value="2">Tisdag</option>
<option value="3">Onsdag</option>
<option value="4">Torsdag</option>
<option value="5">Fredag</option>
</select>
<select name="Tid" id="Tid">
<option value="1">07:00</option>
<option value="2">08:00</option>
<option value="3">09:00</option>
<option value="4">10:00</option>
<option value="5">11:00</option>
<option value="6">12:00</option>
<option value="7">13:00</option>
<option value="8">14:00</option>
<option value="9">15:00</option>
<option value="10">16:00</option>
<option value="11">17:00</option>
<option value="12">18:00</option>
</select>
<input type="submit" name="submit" id="submit" value="Boka" />
</body>
</html>
You're missing the <form> tag. It should be wrapped around all your form-data (select, input) etc. Then you will fetch it using either $_GET or $_POST or even $_REQUIRE
Example (change site.php to whatever you please):
<html>
<head>
<title>title</title>
</head>
<body>
<form method="post" action="site.php">
<select name="Ar" id="Ar">
<option value="1">2014</option>
<option value="2">2015</option>
<option value="3">2016</option>
<option value="4">2017</option>
<option value="5">2018</option>
<option value="6">2019</option>
</select>
<select name="Manad" id="Manad">
<option value="1">Januari</option>
<option value="2">Februari</option>
<option value="3">Mars</option>
<option value="4">April</option>
<option value="5">Maj</option>
<option value="6">Juni</option>
<option value="7">July</option>
<option value="8">Augusti</option>
<option value="9">September</option>
<option value="10">Oktober</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="Dag" id="Dag">
<option value="1">Mandag</option>
<option value="2">Tisdag</option>
<option value="3">Onsdag</option>
<option value="4">Torsdag</option>
<option value="5">Fredag</option>
</select>
<select name="Tid" id="Tid">
<option value="1">07:00</option>
<option value="2">08:00</option>
<option value="3">09:00</option>
<option value="4">10:00</option>
<option value="5">11:00</option>
<option value="6">12:00</option>
<option value="7">13:00</option>
<option value="8">14:00</option>
<option value="9">15:00</option>
<option value="10">16:00</option>
<option value="11">17:00</option>
<option value="12">18:00</option>
</select>
<input type="submit" name="submit" id="submit" value="Boka" />
</form>
</body>
</html>
PHP example:
if(isset($_POST['Ar'])) { // Make sure it's sent
$year = $_POST['Ar'];
echo "År: " . htmlentities($year); // Output (htmlentities for safety when outputting)
$month = $_POST['Manad'];
echo "Månad: " . htmlentities($month);
}
I have an html form that I have been using to POST to a php form, this saves the posted data into the database. I am now loading the data back into the form when I click edit, this works fine for the text fields as I can just use
value="<?php echo $somefield ?>"
The problem is im not sure how to re select my dropdown menu. The menu looks like this and is used for selecting a category, but when the page reloads nothing happens and the dropdown isn't reloaded.
<select name="category" id="category">
<option>- Select A Category -</option>
<optgroup label="Tractors">
<option value="Tractor">Tractor</option>
<option value="Compact">Compact</option>
<option value="Forklift">Forklift</option>
<option value="Load All">Load All</option>
<option value="Loader">Loader</option>
<option value="Maniscopic">Maniscopic</option>
<option value="Masted">Masted</option>
<option value="Piviot">Piviot</option>
<option value="Telescopic">Telescopic</option>
<option value="UTV">UTV</option>
</optgroup>
<optgroup label="Machinery">
<option value="Attachments">Attachments</option>
<option value="Bale Handling">Bale Handling</option>
<option value="Cultivation Equipment">Cultivation Equipment</option>
<option value="Drills">Drills</option>
<option value="Feeders">Feeders</option>
<option value="Fertlizer Spreaders">Fertlizer Spreaders</option>
<option value="Grass Harrows">Grass Harrows</option>
<option value="Grassland Equipment">Grassland Equipment</option>
<option value="Hedge Cutters">Hedge Cutters</option>
<option value="Mowers">Mowers</option>
<option value="Muck Spreaders ">Muck Spreaders </option>
<option value="Ploughs">Ploughs</option>
<option value="Post Hammers">Post Hammers</option>
<option value="Power Harrows">Power Harrows</option>
<option value="Rakes">Rakes</option>
<option value="Rolls">Rolls</option>
<option value="Rotovators">Rotovators</option>
<option value="Shredders">Shredders</option>
<option value="Splitters">Splitters</option>
<option value="Sprayers">Sprayers</option>
<option value="Spreaders">Spreaders</option>
<option value="Tankers">Tankers</option>
<option value="Tedders">Tedders</option>
<option value="Toppers">Toppers</option>
<option value="Trailers">Trailers</option>
<option value="Wrappers">Wrappers</option>
</optgroup>
<optgroup label="Forklifts">
</optgroup>
</select>
<?php
echo '<select>';
foreach( $names as $name )
echo '<option value="'.$name.'" '.($name==$selected?' selected="selected"':'').'>'.$name.'</option>'
echo '</select>';
?>
When building the list the selected option should have the attribute selected="selected".
I have the following date picker with 3 different select ids
<form id="testform" method="get" action="../Untitled-1.html">
<select id="date-sel-dd" name="date-sel-dd">
<option value="-1">Day</option>
<option value="1">1st</option>
<option value="2">2nd</option>
<option value="3">3rd</option>
<option value="4">4th</option>
<option value="5">5th</option>
<option value="6">6th</option>
<option value="7">7th</option>
<option value="8">8th</option>
<option value="9">9th</option>
<option value="10">10th</option>
<option value="11">11th</option>
<option value="12">12th</option>
<option value="13">13th</option>
<option value="14">14th</option>
<option value="15">15th</option>
<option value="16">16th</option>
<option value="17">17th</option>
<option value="18">18th</option>
<option value="19">19th</option>
<option value="20">20th</option>
<option value="21">21st</option>
<option value="22">22nd</option>
<option value="23">23rd</option>
<option value="24">24th</option>
<option value="25">25th</option>
<option value="26">26th</option>
<option value="27">27th</option>
<option value="28">28th</option>
<option value="29">29th</option>
<option value="30">30th</option>
<option value="31">31st</option>
</select>
<select id="date-sel-mm" name="date-sel-mm">
<option value="-1">Month</option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select id="date-sel" name="date-sel">
<option value="-1">Year</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
</select>
<input type="submit" name="submit" id="submit" value="Submit" />
I need to get the values from these 3 differnt select fields and post it with the form to a new named: 'arrival'.
When I submit to the page I want my url to look like:
mydomain.php?arrival=date-sel-dd/date-sel-mm/date-sel
You could use an array.
Rename all select with arrival[].
In your php page you can get that value as an array. Try:
print_r($_POST['arrival']);
If you want to join the date use:
$date = implode('/', $_POST['arrival']);
header('Location: mydomain.php?arrival=' . $date);