i have a simple drop down select menu.
<div id="select">
<select class="select">
<option value="year 1">year 1</option>
<option value="year 2">year 2</option>
<option value="year 3">year 3</option>
</select>
</div>
How do i take the value that the user selects and store it into a php variable?
in somephpfile.php
$selected = $_POST['somename'];
html
<form action="somephpfile.php" method="post">
<div id="select">
<select class="select">
<select name="somename"> <!-- you missed this -->
<option value="year 1">year 1</option>
<option value="year 2">year 2</option>
<option value="year 3">year 3</option>
</select>
</div>
</form>
you missed the "name" attribut in the select and the form tag. Try this:
<HTML><BODY>
<?PHP
$sel_year= $_POST['select'];
echo $sel_year
?>
<FORM method="post" action="...your-php-file-name-here...">
<div id="select">
<select name="select">
<option value="year 1">year 1</option>
<option value="year 2">year 2</option>
<option value="year 3">year 3</option>
</select>
</div>
</FORM>
</BODY></HTML>
<form action="" method="post">
<div id="select">
<select class="select" name="selectoptionname">
<option value="year 1">year 1</option>
<option value="year 2">year 2</option>
<option value="year 3">year 3</option>
</select>
</div>
</form>
when form submits you can get the value of selected option using $_POST['selectoptionname']
put it in a form , then use $_POST['select']
Related
I wonder if anyone can help my problem, in which way I can get value from combobox selection into next url by clicking so I can make it as a parameter to the pdf report.
this is my code to add some combobox :
<form method="GET">
<label class="col-sm-3 control-label">Bulan</label>
<div class="col-sm-2">
<select name="bln" class="form-control">
<option value="1">Januari</option>
<option value="2">Februari</option>
<option value="3">Maret</option>
<option value="4">April</option>
<option value="5">Mei</option>
<option value="6">Juni</option>
<option value="7">Juli</option>
<option value="8">Agustus</option>
<option value="9">September</option>
<option value="10">Oktober</option>
<option value="11">November</option>
<option value="12">Desember</option>
</select>
</div>
<br>
<br>
<label class="col-sm-3 control-label">Tahun</label>
<div class="col-sm-2">
<select name="thn" class="form-control">
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
<option value="2021">2021</option>
<option value="2022">2022</option>
<option value="2023">2023</option>
<option value="2024">2024</option>
<option value="2025">2025</option>
</select>
</div>
</form>
<?php
if (isset($_GET['bln'])) {
$bln = $_GET['bln'];
$thn = $_GET['thn'];
}
?>
<a class="btn btn-success" href="rep-cuti-tahunan-all.php?bln="$bln"&thn="$thn"">Print</a>
so I would like to put $bln and $thn into <a class="btn btn-success" href="rep-cuti-tahunan-all.php?bln="$bln"&thn="$thn"">Print</a>
and get my report in pdf exactly according to that parameters
any suggestions?
You don't have to add it as a parameter.Just change your form like this.
<form method="GET" action ="rep-cuti-tahunan-all.php">
....
</form>
then on your php file, you fetch the selected value.
<?php
....
if (isset($_GET['bln'])) {
$bln = $_GET['bln'];
$thn = $_GET['thn'];
}
....
//Do your print method ...
?>
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>
I have a form with several <select> that have the same name and an onChange="document.forms['form_mes_reservations'].submit();" on all of them. Therefore, when I select an option from one of them, the page reloads and there is some PHP treatment done.
This is an example :
<form method="post" id="form_process">
<select name="processed" onChange="document.forms['form_process'].submit();">
<option value="1_choose">Please choose...</option>
<option value="1_yes">Yes</option>
<option value="1_no"></option>
</select>
<select name="processed" onChange="document.forms['form_process'].submit();">
<option value="2_choose">Please choose...</option>
<option value="2_yes">Yes</option>
<option value="2_no"></option>
</select>
<select name="processed" onChange="document.forms['form_process'].submit();">
<option value="3_choose">Please choose...</option>
<option value="3_yes">Yes</option>
<option value="3_no"></option>
</select>
<select name="processed" onChange="document.forms['form_process'].submit();">
<option value="4_choose">Please choose...</option>
<option value="4_yes">Yes</option>
<option value="4_no"></option>
</select>
</form>
What I'd like to know is this : is there a way to know which select has triggered the onChange ? Let me explain : in the $_POST['processed'], I get ALL the selected options, so if I have only selected "3_yes", I'll get something like this :
1_choose
2_choose
3_yes
4_choose
Is it possible to only have "3_yes" as a result ? Potentially, this is going to be a very long list of selects and I don't want to check all of them for changes...
Just make all select elements as array and check which is selected:
HTML:
<form method="post" id="form_process" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="processed[]" onChange="document.forms['form_process'].submit();">
<option value="1_choose">Please choose...</option>
<option value="1_yes">Yes</option>
<option value="1_no"></option>
</select>
<select name="processed[]" onChange="document.forms['form_process'].submit();">
<option value="2_choose">Please choose...</option>
<option value="2_yes">Yes</option>
<option value="2_no"></option>
</select>
<select name="processed[]" onChange="document.forms['form_process'].submit();">
<option value="3_choose">Please choose...</option>
<option value="3_yes">Yes</option>
<option value="3_no"></option>
</select>
<select name="processed[]" onChange="document.forms['form_process'].submit();">
<option value="4_choose">Please choose...</option>
<option value="4_yes">Yes</option>
<option value="4_no"></option>
</select>
</form>
PHP:
<?php
foreach($_POST['processed'] AS $key => $value){
if(strpos($value, 'choose') !== false){
unset($_POST[processed][$key]);
}
}
print_r($_POST['processed']);
?>
Output:
Array
(
[1] => 2_yes
)
I have this select button:
<form method="post">
<label>
<select id="label" name="challengeX" style="margin-top:150px;">
<option selected value="0"> Global Statistics </option>
<option value="1">Challenge 1</option>
<option value="2">Challenge 2</option>
<option value="3">Challenge 3</option>
</select>
</label>
</form>
In the same page, few lines bellow, I have:
<div id="challenge">
<?php
$Ch = $_POST['challengeX'];
echo "Challenge: ".$Ch;
showSomething($Ch,1,1);
?>
</div>
But when I change the option, it didn't change the post value.
$Ch = $_POST['challengeX'];
won't get value until you submit the form. Add a submit button to your form.
<form method="post" action="">
<label>
<select id="label" name="challengeX" style="margin-top:150px;">
<option selected value="0"> Global Statistics </option>
<option value="1">Challenge 1</option>
<option value="2">Challenge 2</option>
<option value="3">Challenge 3</option>
</select>
</label>
<input type="submit" value="Submit">
</form>
And access the form values in the same page only if the form is submitted.
<div id="challenge">
<?php
if(isset($_POST)) // checks whether any value is posted
{
$Ch = $_POST['challengeX'];
echo "Challenge: ".$Ch;
showSomething($Ch,1,1);
}
?>
</div>
you need to submit form on change of dropdown.
Change html like this:
<form method="post">
<label>
<select id="label" name="challengeX" style="margin-top:150px;" onchange="this.form.submit()">
<option selected value="0"> Global Statistics </option>
<option value="1">Challenge 1</option>
<option value="2">Challenge 2</option>
<option value="3">Challenge 3</option>
</select>
</label>
</form>
for your php execution you can try like this:
<div id="challenge">
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$Ch = $_POST['challengeX'];
echo "Challenge: ".$Ch;
showSomething($Ch,1,1);
function showSomething($Ch,1,1){
//do your stuff
}
}
?>
</div>
PHP runs on the server and delivers HTML (or other data) to the browser.
If you want to process the form data with PHP then you must include it in a new HTTP request (typically by submitting the form) and have PHP generate a new page using that data.
Alternatively, if you want to process the data on the client then you will need to use a programming language that is supported in the browser. Unless you want to start using plugins (or browser specific technologies), that limits you to JavaScript. You can bind a change event listener to the select element and then manipulate the DOM with the results.
In the way you can use Javascript. If you dont want to use any server like PHP or something
<form method="post">
<label>
<select id="label" name="challengeX" style="margin-top:150px;">
<option selected value="0"> Global Statistics </option>
<option value="1">Challenge 1</option>
<option value="2">Challenge 2</option>
<option value="3">Challenge 3</option>
</select>
<input type="submit" /> /* add this line */
</label>
</form>
By Javascript
<select id="label" name="challengeX" style="margin-top:150px;" onChange="getSelect(this)">
<option selected value="0"> Global Statistics </option>
<option value="1">Challenge 1</option>
<option value="2">Challenge 2</option>
<option value="3">Challenge 3</option>
</select>
<div id="resultSelect"></div>
<script>
function getSelect(thisValue){
document.getElementById('resultSelect').innerHTML=thisValue.options[thisValue.selectedIndex].text;
}
</script>
i am trying to add a text field using prestashop CMS option, i can easily save drop downs that i have created, but when i try to save the text field it gives me this error
The content field is invalid..
Following is my HTML Block.
<h1>Sell your item</h1>
<p>Select Category:</p>
<select class="selectBox selectBox-dropdown selectProductSort" name="catgeory_dropdown">
<option value="">-- Select Category</option>
<option value="category1">Category 1</option>
<option value="category2">Category 2</option>
<option value="category3">category 3</option>
</select>
<p>
<input id="item_name" class="search_query ac_input" autocomplete="off" name="item_name" type="text" /></p>
<p>Select Category:</p>
<select class="selectBox selectBox-dropdown selectProductSort" name="catgeory_dropdown">
<option value="">-- Select Category</option>
<option value="category1">Category 1</option>
<option value="category2">Category 2</option>
<option value="category3">category 3</option>
</select>
It happened to me the same error message when I tried to put input fields in contents.