I have a week schedule. when I am trying to select the already selected item it will get disabled. In my form I am looking to edit the weekdays. If monday is selected then it can't be selected again.
<?
$i=1;
foreach($shop_timing->result() as $name)
{?>
<br>
<input type="hidden" id="shop_time_id" name="time<?echo $i;?>" value="<?echo $name->shop_time_id;?>">
<select class="right" data-placeholder="select your category" id="select_7<?echo $i?>" data-rel="chosen" name="day<?echo $i;?>" >
<option <?php if($name->working_day=="Monday"){?> selected="selected" <?}?> >Monday</option>
<option <?php if($name->working_day=="Tuesday"){?> selected="selected" <?}?>>Tuesday</option>
<option <?php if($name->working_day=="Wednesday"){?> selected="selected" <?}?>>Wednesday</option>
<option <?php if($name->working_day=="Thursday"){?> selected="selected" <?}?>>Thursday</option>
<option <?php if($name->working_day=="Friday"){?> selected="selected" <?}?>>Friday</option>
<option <?php if($name->working_day=="Saturday"){?> selected="selected" <?}?>>Saturday</option>
<option <?php if($name->working_day=="Sunday"){?> selected="selected" <?}?>>Sunday</option>
-->
</select>
<div class="bootstrap-timepicker">
<div class="input-group">
<input type="text" class="timepicker starttime" value="<?echo $name->working_start_time?>" name="timefrom<?echo $i;?>" id="timefrom" placeholder="time"/>
</div>
</div>
<div class="bootstrap-timepicker">
<div class="input-group">
<input type="text" class="timepicker end" value="<?echo $name->working_end_time?>" name="endtime<?echo $i;?>" id="endtime" placeholder="time"/>
</div>
</div>
<? $i++; } ?>
<input type="hidden" id="count" name="count" value="<?echo $count;?>">
<?
for($j=1;$j<=(7-$count);$j++)
{?>
<select class="right" data-placeholder="select your category" id="select_7<?echo $i?>" data-rel="chosen" name="day<?echo $i;?>">
<option disabled="disabled" selected="selected">Day</option>
<option>Monday</option>
<option>Tuesday</option>
<option>Wednesday</option>
<option>Thursday</option>
<option>Friday</option>
<option>Saturday</option>
<option>Sunday</option>
</select>
<div class="bootstrap-timepicker">
<div class="input-group">
<input type="text" class="timepicker starttime" name="timefrom<?echo $i;?>" id="starttime3" placeholder="time"/>
</div>
</div>
<div class="bootstrap-timepicker">
<div class="input-group">
<input type="text" class="timepicker end" name="endtime<?echo $i;?>" id="endtime3" placeholder="time"/>
</div>
</div>
<? $i++; } ?>
You are trying to select multiple items in a dropdown but you have not told the dropdown that multiple selection is allowed. I think this is confusing things
On your <select..> add the multiple attribute like so
<select multiple
class="right"
data-placeholder="select your category"
id="select_7<?echo $i?>"
data-rel="chosen"
name="day<?echo $i;?>" >
Well first of all for the purpose of DRY, don't repeat yourself. The easy way to build your select is with an array and a loop . Typically it would take this form
<?php
function printOptions( $selected_value )
$days = array(
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday"
);
foreach( $days as $day ){
if($selected_value == $day ){
$selected = ' selected="selected"';
}else{
$selected = '';
}
echo '<option value="'.$day.'"'.$selected.' >'.$day.'</option>'
}
}
?>
Then you can go
<select class="right day_selection" data-placeholder="select your category" id="select_7<?echo $i?>" data-rel="chosen" name="day<?echo $i;?>" >
<?php printOptions( $name->working_day ) ?>
</select>
Isn't that much nicer looking
That settled this is largely a javascript problem so with jquery you would want to do something like this:
var selectors = $('day_selection'); //cache select elments
$('.day_selection').change( function(){
var current = $(this).prop('id');
var current_value = $(this).val();
$.each( selectors, function(i,v){
if($(this).prop('id') != current ){
$(this).find('option[value="'+current_value+'"]').prop('disabled', true );
}
});
});
now you will have to find a way to un-disable them but that should point you in the right direction. Likely you could make an object to store the values in and then when they change look up that value and disable,false them.
Like this
var selected = {
"select_71" : "Monday" //Id : value
}
And below this
$(this).find('option[value="'+current_value+'"]').prop('disabled', true );
Add
if( selected.current ){
$(this).find('option[value="'+selected.current+'"]').prop('disabled', false );
}
And outside ( after ) the each loop add:
selected.current = current_value;
On a side note an Idea that occurs to me is why have the selects at all, why not just have blocks with a checkbox and the time range, checking the checkbox selects the day. Then there is no need to worry about it and the order is fixed.
Thursday 8/20/2015 [ ] select
[_ start time ] to [ end time _]
Friday 8/21/2015 [ ] select
[_ start time ] to [ end time _]
etc...
Related
Here is the code that I want to include in my wordpress content and display an html file depending on the submitted values. What do I need to do to make this work? I'm new to wordpress so any help would be very much appreciated. I have already installed a plugin for php to work with my Wordpress site. Thank you in advance
<h3>Province:</h3>
<select name="province" >
<option value="A" >A</option>
<option value="B" >B</option>
<option value="C" >C</option>
<option value="D" >D</option>
<option value="E" >E</option>
</select>
<h3>Year:</h3>
<?php
$years = array();
for ($i = 2018; $i > 2012; $i--)
{
$years[] = $i;
}
echo "<select name='year'>";
foreach($years as $option){
echo "<option value='{$option}'>{$option}</option>";
}
echo "</select>";
?>
<h3>Month:</h3>
<select name="month" >
<option value="January" >January</option>
<option value="February" >February</option>
<option value="March" >March</option>
<option value="April" >April</option>
<option value="May" >May</option>
<option value="June" >June</option>
<option value="July" >July</option>
<option value="August" >August</option>
<option value="September" >September</option>
<option value="October" >October</option>
<option value="November" >November</option>
<option value="December" >December</option>
</select>
<div>
<input type="submit" name="submit" value="Submit" class="btnSubmit" />
</div>
</div>
<div >
<?php
if($_GET){
echo "<strong>".$_GET['province']." Price Monitoring as of ".$_GET['month']." ".$_GET['year']."</strong>"; }
?>
</div>
</form>
<div>
/*access file directory using submitted fields */
<?php
if($_GET){
echo '<embed src=wp-content/uploads/pricewatch/'.$_GET['province'].''.$_GET['month'].''.$_GET['year'].'.htm width="700" height="800"{ # code...}/>';
}
?>
</div>
I mean, it looks like you're relatively close, it mostly looks like your <embed> tag is messed up, thus not working.
Take a look at this link: https://xhynk.com/KrutSednar.php
Leave the Year value as 2018, as I've only create a 2018.htm
If I were you, I would use file_get_contents() instead of <embed> - but either method (or even <iframe> would work to pull in your HTML file.
I've taken the liberty of cleaning up your code a bit, but the main piece to note is that you could replace your <embed> line with this:
if( $_GET ) echo file_get_contents( '/wp-content/uploads/pricewatch/$province/$month/$year.htm' );
Here's the updated code. A few notes:
You didn't have a <form> in your example so I made this action the current URL.
I simplified your $year loop
I turned your $months into a similar loop.
I personally like to loop through arrays (like $_GET) and turn $_GET['year'] into $year, that's what the $key => $val loop is for.
In my code at the bottom, you may need to update the path of the .htm files, I added slashes because I assumed they'd be there, but you can modify that string as needed.
Hope that makes sense!
<form action="<?= ( isset($_SERVER['HTTPS'] ) ? "https" : "http" ) . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; ?>">
<div>
<h3>Province:</h3>
<select name="province">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
<option value="E">E</option>
</select>
<h3>Year:</h3>
<select name="year">
<?php for( $i = 2018; $i > 2012; --$i ) echo "<option value='$i'>$i</option>"; ?>
</select>
<h3>Month:</h3>
<select name="month">
<?php for( $m = 1; $m <= 12; ++$m ){
$month = date( 'F', mktime( 0, 0, 0, $m, 1 ) );
echo "<option value='$month'>$month</option>";
} ?>
</select>
<div>
<input type="submit" name="submit" value="Submit" class="btnSubmit" />
</div>
</div>
<div>
<?php
if( $_GET ){
foreach( $_GET as $key => $val ) ${$key} = $val;
echo "<strong>$province Price Monitoring as of $month $year</strong>";
}
?>
</div>
</form>
<div>
<?php
if( $_GET ) echo file_get_contents( '/wp-content/uploads/pricewatch/$province/$month/$year.htm' );
//if( $_GET ) echo "<embed src='/wp-content/uploads/pricewatch/$province/$month/$year.htm' width='700' height='800'";
?>
</div>
I want to keep the selected values in select box after search .This is a vehicle search filter page and Page is coded using php and connected with database.
Database have 2 columns for both options that is driver age for 21-24 and driver_age for 25+ as some vehicles also available for both age of drivers
code below
<script>
$('#driver').change(function() {
if($('#driver option:selected').val() == '21-24') {
$('#driver').attr('name','driverage');
}
if($('#driver option:selected').val() == '25+') {
$('#driver').attr('name','driver_age');
}
});
</script>
<form id="myform" method="GET" action="">
<div class="fields">
<p>Vehicle Type</p>
<select class="car" name="car_type" id="car_type">
<option value="0">Select Vehicle</option>
<?php if(count($vehicleType) > 0 ){
foreach($vehicleType as $vt){ ?>
<option value="<?php echo $vt ?>" <?=isset($_GET['car_type'])&&$_GET['car_type']==$vt?'selected':'';?> ><?php echo $vt ?></option>
<?php }
} ?>
</select>
</div>
<div class="fields">
<p>Age of Youngest Driver</p>
<select class="half" id="driver" name="">
<option value="21-24">21-24</option>
<option value="25+">25+</option>
</select>
</div>
<input type="hidden" name="search" />
<div class="fields" style="text-align:center">
<input type="submit" value="Search" class="mitsub" />
</div>
</form>
Thanks and please help
You can add a conditional statement inside your foreach() that adds selected attribute to option. This will ensure that the selected value is selected in the list of options.
<?php
if(count($vehicleType) > 0 ){
foreach($vehicleType as $vt){
echo "<option value='$vt'";
if(isset($_GET['car_type']) && $_GET['car_type'] == $vt){
echo " selected";
}
echo ">$vt</option>\r\n";
}
}
?>
You can do this all in one, you just have to make sure the logic is correct.
echo "<option value='$vt'" . ((isset($_GET['car_type'] && $_GET['car_type'] == $vt) ? " selected" : "") . ">$vt</option>\r\n";
I just find it easier to work with a full if statement.
User have some options, upon selecting one of them, I want to show more options which will depend on first selected option. Say, user has options to select the number of gates, like 1 or 2. Upon selecting a number I want to show options of all the gates lower than that number. That is,
if 1 is selected, show options of only gate 1.
if 2 is selected, show options of gate 2 and gate 1.
I have most of the variables within my phpmyadmin for storage purposes to avoid having to create alot of variables in the code. Just want some suggestions and if you see anything I can improve let me know.
<div class="form-div-element">
<label># of Gates</label>
<select class="gates-change" name="no_gate" required>
<option value="">Select Gate</option>
<option value="28">1 Gate</option>
<option value="29">2 Gates</option>
</select>
</div>
<?php
if($result)
{
foreach($result as $row)
{
if($row->id == 31 || $row->id == 32 || $row->id == 33)
{?>
<div class="form-div-element ecl-variation ecl-variation<?php echo $row->id;?>" style="display:block!important">
<?php }
else
{?>
<div class="form-div-element ecl-variation ecl-variation<?php echo $row->id;?>">
<?php }?>
<label><?php echo $row->variation_name;?></label>
<?php
if($row->variation_name == 'Stops')
{?>
<input type="hidden" name="stopvariationid" value="<?php echo $row->id;?>" id="stopvariationid"/>
<?php }
?>
<?php
$var_value = (explode("|",$row->variation_value));
$var_condition = $row->conditions;
$arr = array('height_convert_configuration');
//if($row->special_features != '')
//{
// check_special_function($var_value,$row->special_features,$var_condition);
//}
//else if($row->variation_type =='selectbox')
if($row->variation_type =='selectbox')
{
if($row->variation_function == 'calculation')
{?>
<select onchange = 'change_variation(this.value,<?php echo $row->id;?>)'>
<option value="">Select Option</option>
<?php for($i=0;$i<count($var_value);$i++)
{?>
<option value="<?php echo $var_value[$i];?>"><?php echo $var_value[$i];?></option>
<?php }?>
</select>
<?php }
else
{ ?>
<select class="gate_datatype" name="gate_type">
<option value="">Select Option</option>
<?php for($i=0;$i<count($var_value);$i++)
{?>
<option value="<?php echo $var_value[$i];?>|<?php echo $row->special_features;?>"><?php echo $var_value[$i];?></option>
<?php }?>
</select>
<?php }
}
else if($row->variation_type =='textbox')
{?>
<?php for($i=0;$i<count($var_value);$i++)
{?>
<?php echo $var_value[$i];?>
<?php }?>
<?php }
else if($row->variation_type =='radiobox')
{?>
<?php for($i=0;$i<count($var_value);$i++)
{?>
<div class="radiobox-cont">
<input onchange = 'change_radio_variation(this,this.value,<?php echo $row->id;?>)' type="radio" name="<?php echo $row->class;?>" value='<?php echo $var_value[$i];?>' /><?php echo $var_value[$i];?>
</div>
<?php }?>
<?php }
else if($row->variation_type =='checkbox')
{?>
<?php for($i=0;$i<count($var_value);$i++)
{?>
<div class="checkbox-cont <?php echo preg_replace('/\s+/', '_', $var_value1[$i]);?>">
<?php if('Cabin Telephone' == $var_value[$i])
{?>
<input checked type="checkbox" onchange="change_check_varitaion(this,this.value,<?php echo $row->id;?>)" name="other_option[]" value='<?php echo $var_value[$i];?>' disabled="disabled" /><?php echo $var_value[$i];?>
<?php }
else
{?>
<input type="checkbox" onchange="change_check_varitaion(this,this.value,<?php echo $row->id;?>)" name="other_option[]" value='<?php echo $var_value[$i];?>' /><?php echo $var_value[$i];?>
<?php }?>
</div>
<?php }?>
<?php }?>
</div>
<?php }
You can do this in two ways first way is to do ajax and second way is using css.
First method suppose this is your select code where you can select gate
<div class="form-div-element">
<label># of Gates</label>
<select id="gates" onchange="change()" class="gates-change" name="no_gate" required>
<option value="">Select Gate</option>
<option value="28">1 Gate</option>
<option value="29">2 Gates</option>
</select>
</div>
// and this is your sub gates options which will be empty at first and its display will be none
<div id="subgates_div" class="form-div-element" style="display:none;">
<label># of Sub Gates</label>
<select id="subgates" class="gates-change" name="sub_no_gate" required>
<option value="">Select Sub Gate</option>
</select>
</div>
on selecting gate what you can do is use ajax to get the sub options of the selected gate like this. in this code your url and my url will be different.
function change() {
var selected = $('#gates').find(":selected").attr("value");
$.ajax({
type: "POST",
url: '<?php echo base_url('get_sub_options') ?>',
dataType: 'json',
data: {category: selected},
success: function (data) {
console.log(data);
//remove disabled from province and change the options
$('#subgates_div').show();
$('select[name="sub_no_gate"]').html(data.subgates);
}
});
}
and your php function should be like this here first i have made an array named subgates. and i have retrieved subgates from database using the value from post. this query might be different in your case. the i have applied foreach loop for sub gates and created a new option element with respective subgate id and subgate name and appended it to array. and at last the array is returned using json_encode
function get_sub_category() {
$data['subgates'] = array();
$subgates = $this->db->get_where('subcategories', array('id' => $_POST['category']))->result();
foreach ($subgates as $key => $val) {
$data['subgates'][] = <<<EOD
<option value='$val->id'>$val->sub_gate_name</option>
EOD;
}
echo json_encode($data);
}
and the other method is using css. to do this you should list all this options of gate and subgates at first. like this
// gates options
<div class="form-div-element">
<label># of Gates</label>
<select id="gates" onchange="change()" class="gates-change" name="no_gate" required>
<option value="">Select Gate</option>
<option value="28">1 Gate</option>
<option value="29">2 Gates</option>
</select>
</div>
//sub gate options one
<div id="subgates-<?php echo $subgates->id; ?>" class="form-div-element" style="display:none;">
<label># of Sub Gates</label>
<select id="subgates" class="gates-change" name="sub_no_gate" required>
<option value="">Select Sub Gate</option>
</select>
</div>
//sub gate option 2
<div id="subgates-<?php echo $subgates->id; ?>" class="form-div-element" style="display:none;">
<label># of Sub Gates</label>
<select id="subgates" class="gates-change" name="sub_no_gate" required>
<option value="">Select Sub Gate</option>
</select>
</div>
// and so on
In this case what you should remember is that your sub gates option div id should be dynamic and display will be none at first
now when you select a gate use onchange and change the display css of respective sub gates like this
function change() {
$(".form-div-element").hide();
var selected = $('#gates').find(":selected").attr("value");
$('#subgates-'+selected).show();
}
hope this will give you some idea and if you have any confusion feel free to ask
All in all it seems to me that your question actually contains 2 questions:
How to dynamically show/hide DOM elements based on user selection
Upon selecting a number I want to show options of all the gates lower than that number.
How to optimize your PHP code
Just want some suggestions and if you see anything I can improve let me know.
Number two is way to broad! Maybe just one quick suggestion: If it works then its fine. Overlooked it fast and seems to be ok.
See my working snippet for number one, which actually only needs a little customization of your existing source code (if any at all). Don't forget its just a mockup; if you need some further help or want some deeper explanations about whats going on then let me know...
jQuery('.form-div-element').not('.ecl-variation').find('select').on('change', function() {
var i = -1,
$conditional = jQuery('.ecl-variation').hide(), // hide in advance
iGates = +(jQuery(this).find('option:selected').attr('data-gates-sum')); // get required gate(s) based on selected options "data-gates-sum"-attribute
// version based on text: `iGates = +($(this).find('option:selected').text().split(' ')[0])` | pro: no additional markup, con: error prone, maintenance
// count up to required gate(s) and make them visible
while ( ++i < iGates ) {
$conditional[i].style.display = 'block';
}
});
.ecl-variation{
display: none; /* hide conditional selects in advance */
}
<!-- minimized mockup -->
<div class="form-div-element">
<label># of Gates</label>
<select>
<option value="">Select Gate</option>
<!-- decided to add a data attribute instead of relying on text which could change more likely (maintenance) -->
<option value="28" data-gates-sum="1">1 Gate</option>
<option value="29" data-gates-sum="2">2 Gates</option>
</select>
</div>
<div class="form-div-element ecl-variation">
<label># of Gates | conditial 1</label>
<select>
<option value="">Select Gate Sub</option>
<option value="3">abc</option>
<option value="4">xyz</option>
</select>
</div>
<div class="form-div-element ecl-variation">
<label># of Gates | conditial 2</label>
<select>
<option value="">Select Gate Sub</option>
<option value="5">123</option>
<option value="6">789</option>
</select>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
How to implement?
.ecl-variation{
display: none; /* hide conditional selects in advance */
}
<body>
<!-- minimized mockup -->
<div class="form-div-element">
<label># of Gates</label>
<select>
<option value="">Select Gate</option>
<option value="28" data-gates-sum="1">1 Gate</option>
<option value="29" data-gates-sum="2">2 Gates</option>
</select>
</div>
<div class="form-div-element ecl-variation">
<label># of Gates | conditial 1</label>
<select>
<option value="">Select Gate Sub</option>
<option value="3">abc</option>
<option value="4">xyz</option>
</select>
</div>
<div class="form-div-element ecl-variation">
<label># of Gates | conditial 2</label>
<select>
<option value="">Select Gate Sub</option>
<option value="5">123</option>
<option value="6">789</option>
</select>
</div>
<!-- YOUR CODE ENDS HERE -->
<!-- load jquery from cdn -->
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
<!-- provide a local copy as fallback in case that cdn is not available -->
<script>window.jQuery||document.write('<script src="path/to/your/local/copy/jquery-1.12.4.min.js"><\/script>')</script>
<!-- implement your custom site specific script(s) inline -->
<script>
(function( $ ) {
$('.form-div-element').not('.ecl-variation').find('select').on('change', function() {
var i = -1,
$conditional = $('.ecl-variation').hide(),
iGates = +($(this).find('option:selected').attr('data-gates-sum'));
while ( ++i < iGates ) {
$conditional[i].style.display = 'block';
}
});
})( jQuery )
</script>
<!-- instead of deploying your scripts inline you can load them also like this:
<script src="path/to/your/app.js"></script>
-->
</body><!-- make sure that your scripts are located just before the closing body tag -->
How can i fetch the data from the option-field and load the chosen option-field into the database ?
<div class="form-group col-md-5">
<label class="control-label">Date of birth:*</label>
<div class="form-group">
<div class="col-md-4">
<select type="text" class="form-control" id="day" >
<option>--Day--</option>
<?php
$day = array(range(1,31));
for ($i = 1; $i <= 31; $i++) {
echo "<option name='day'>".$i."</option>";
}
?>
</select>
</div>
<div class="col-md-4">
<select type="text" class="form-control" id="month">
<option>--Month--</option>
<?php
for ($i = 1; $i <= 12; $i++) {
echo "<option name='month'>".$i."</option>";
}
?>
</select>
</div>
<div class="col-md-4">
<select type="text" class="form-control" id="year">
<option>--Year--</option>
<?php
for ($i = 1900; $i <= 2016; $i++) {
echo "<option name='year'>".$i."</option>";
}
?>
</select>
</div>
</div>
</div>
I know i can use https://eonasdan.github.io/bootstrap-datetimepicker/ cause im using bootstrap. but there it's the same. i dont know how to fetch the choosen data.
You just need to add name attribute in <select> box and add $i value in <option> as:
<select type="text" class="form-control" id="day" name='day'>
<option>--Day--</option>
<?php
$day = array(range(1,31));
for ($i = 1; $i <= 31; $i++) {
?>
<option value="<?=$i?>"><?=$i?></option>
<?php
}
?>
</select>
Here i am using name='day' in <select> tag, and value="<?=$i?>" in <option> tag.
Same as for YEAR and MONTH fields.
You need to change two things here.
First, give name to the <select> instead of <option>.
Second set the value attribute of the <option> to get the value of selected option.
So the code for selection box you've written will look something like this,
<select type="text" class="form-control" id="year" name="year">
<option>--Year--</option>
<?php
for ($i = 1900; $i <= 2016; $i++) {
echo "<option value='".$i."'>".$i."</option>";
}
?>
</select>
Now if the form method is POST access the year value in php script using $_POST and if it's GET then access it using $_GET.
I don't know your server side part of code but here you missing values on option fields. This value is what you save in database. So if everything else is okay with your code you should make something like this:
<label class="control-label">Date of birth:*</label>
<div class="form-group">
<div class="col-md-4">
<select name="day" type="text" class="form-control" id="day" >
<option>--Day--</option>
<?php
$day = array(range(1,31));
for ($dayOfBirth = 1; $dayOfBirth <= 31; $dayOfBirth++) {
echo '<option value="'.$dayOfBirth.'">"'.$dayOfBirth.'"</option>';
}
?>
</select>
</div>
<div class="col-md-4">
<select name="month" type="text" class="form-control" id="month">
<option>--Month--</option>
<?php
for ($monthOfBirth = 1; $monthOfBirth <= 12; $monthOfBirth++) {
echo '<option value="'.$monthOfBirth.'">"'.$monthOfBirth.'"</option>';
}
?>
</select>
</div>
<div class="col-md-4">
<select name="year" type="text" class="form-control" id="year">
<option>--Year--</option>
<?php
for ($yearOfBirth = 1900; $yearOfBirth <= 2016; $yearOfBirth++) {
echo '<option value="'.$yearOfBirth.'">"'.$yearOfBirth.'"</option>';
}
?>
</select>
</div>
</div>
Check Points for getting value form the Select tag
If you need to pull out the data from the select tag you have to check for the following conditions.
Whether you have provided the name for the select tag.
Whether you have provided the value for the option fields.
if so you do the above two alone you can fetch out or pull out the data from the select tag.
Example:
Select tag: With name and option values
<select name="age">
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
Then in the PHP you can fetch out the data like this.
<?php
if(isset($_POST['age'])
{
echo $_POST['age'];
}
?>
I have a select statement in one php file. Once users select their filter option, there is another button they can click that will take them to a new page. This new page is another php file. I would like the filter selected from the first php file to carry over to the 2nd php file.
Here is the select statement:
<form name="CapYTimeForMajorInitiatives" method="post">
<b>Select Date Range: </b> <select id="daterange" name="daterange" required>
<option <?php if ($daterange == '' ) echo "selected"; ?> value='' >Select a date range</option>
<option <?php if ($daterange == 'currentqtr' ) echo "selected"; ?> value='currentqtr' >Current Quarter</option>
<option <?php if ($daterange == '30days' ) echo "selected"; ?> value='30days' >Last 30 Days</option>
<option <?php if ($daterange == 'ytd' ) echo "selected"; ?> value='ytd' >Year to Date</option>
</select>
</br>
</br>
<input name="submit" type="submit" value="Submit" onclick="myFunction()"/>
And here is the script for the new window:
<p>Click the button for associate breakdown.</p>
<button onclick="mySQL1()">Associate Breakdown</button>
<script>
function mySQL1() {
window.open("http://blahblahblah.php");
}
</script>