I have a simple form made in PHP, I am trying to pass the select value in the page mentioned in the action URL,
<form action="filtertable.php" method="post">
<select class="form-select" name="filtercategory" aria-label="Default select example"
onchange="this.form.submit()">
<option selected>Select Category</option>
<option value="<?php echo $roww["c_id"]; ?>"><?php echo $roww["cname"]; ?></option>
</select>
</form>
when the user selects on any select box it will go to the page filtertable.php, and from there am trying to get the selected value like this:
<?php
$filtercategory=$_POST['filtercategory'];
However it doesn't work, can anyone please tell me what is wrong in here, thanks in advance
Related
I have two forms both using select so my values are within dropdown. I want to be able to submit the two forms without the use of submit buttons.
The first form submits using the onchange="this.form.submit()"
method. However, the second form doesn't submit when an option selected.
How do I make each form submit using onchange="this.form.submit()"?
//This form submits using onchange="this.form.submit()"
<select class="clientselect" name="clientlist" id="clientlist" onchange="this.form.submit()">
<option value="">All Clients</option>
<? echo makeClientList($conn); ?>
</select>
//This for does'nt sybmit using onchange="this.form.submit()"
<select class="clientselect" name="filterstatus" id="filterstatus" onchange="this.form.submit()">
<option value="">Filter by Status</option>
<? echo getStatus($conn); ?>
</select>
If you give each form a name attribute then you can reference that in your onchange, for example:
onchange="document.form1.submit()"
You'll need to change form1 for the name of each form
I'm generating dropdown inputs with php simple html dom. I have some values from database and according them i will add 'selected' value into my select->option dom elements.
<select name="myDropDown" id="someID">
<option value="someValue1">Value1Value</option>
<option value="someValue2">Value2Value</option>
<option value="someValue3">Value3Value</option>
</select>
this is the default one. i would like to add value like this, check on option 2 :
<select name="myDropDown" id="someID">
<option value="someValue1">Value1Value</option>
<option value="someValue2" selected>Value2Value</option>
<option value="someValue3">Value3Value</option>
</select>
and while doing that i want to use my plugin.
<?php
$html = new simple_html_dom();
$html->load('
<select name="myDropDown" id="someID">
<option value="someValue1">Value1Value</option>
<option value="someValue2">Value2Value</option>
<option value="someValue3">Value3Value</option>
</select>
');
echo $html;
?>
Everything works nicely until here. Yeah now i need to insert selected into my second option. I don't know how to do this with PHP Simple HTML DOM, or i'm missing something in the documentation : http://simplehtmldom.sourceforge.net/manual.htm#section_access
What i have tried so far and got many errors in my php section :
<?php
$html = new simple_html_dom();
$html->load('
<select name="myDropDown" id="someID">
<option value="someValue1">Value1Value</option>
<option value="someValue2">Value2Value</option>
<option value="someValue3">Value3Value</option>
</select>
');
//here's where i'm trying to reach the child nodes :
$ret = $html->getElementById('someID');
$ret->children(2)->GOTTADOSOMETHINGHEREANDIREALLYDUNNO;
echo $html;
?>
By the way, if you offer another easy way to do this, i'd appreciate.
Thank you in advance !
With minimal research you can figure this out for yourself.
$ret->children(2)->selected = true;
Why you use simple_html_dom and not simply a template file (with PHP)?
<select name="test" <?php if($selected){echo 'selected'}?> />
Or even better Smarty.
<select name="test" {if $selected}selected{/if} />
Simple_html_dom is a class for parsing complex html documents like exchanging image urls or something like that. I cant' see any reason why you need to use this class.
for getting Dropdown Element Selected Option with Simple HTML DOM
just try this simple and easy method
$element = $html->find('#selectIDGoesHere',0)->find('option');
foreach($element as $elemen) {
echo "Display text:".($elemen->plaintext)."<br>";
echo "value:".($elemen->value)."<br>";
}
In the following form, when a country option is selected, it appends ?country=<value> to the URL.
I am attempting to create an 'All' option which should append nothing. I have used value='' on the 'All' option, however it still appends ?country= onto the URL when selected.
Is it possible to remove '?country=', so that nothing at all is added onto the URL when 'All' is selected?
<form method="GET" action="">
<select name="country">
<option selected disabled value=''>Country</option>
<option value="">All</option>
<option>Austria</option>
<option>Denmark</option>
<option>Poland</option>
<input type="hidden" name="date" value="<?php echo $the_date ?>" />
</select>
</form>
N. B. I also have a hidden date option, so the complete URL may also have an &date=<value> too.
You are looking for POST.
<form method="post" action="">
<select name="country">
<option selected disabled value=''>Country</option>
<option value="">All</option>
<option>Austria</option>
<option>Denmark</option>
<option>Poland</option>
<input type="hidden" name="date" value="<?php echo $the_date ?>" />
</select>
</form>
<?php
if(isset($_POST['country']))
{
echo '<br>Country: '.$_POST['country'];
echo '<br>Date: '.$_POST['date'];
}
?>
You can use ajax form submit, this way the browser URL will not change.
But the thing is the URL to which the request will go it will take the parameters as query sting, but this will not change the browser URL it will go in background.
I am trying to set value from php the option selected in a drop down list in html.
can anyone tell me how to give the "selected" attribute as the answer is generated dynamically
<select form="onsite_assessment" class="form-control" id="onsite_assessment">
<option value="no">NO</option>
<option value="yes">YES</option>
</select>
In the above code if the user has selected No in the previous session. i want to display that option by default.
This is just some general code which can be shaped for your needs. As I can't see all your code I cannot give a FULL answer. Basically you need to store the users' choice and retrieve this in a variable whenever needed, either string or Boolean (true/false). In the example I will show this using a string.
<?php
$user_choice = 'yes';
?>
<select form="onsite_assessment" class="form-control" id="onside_assessment">
<option value="no" <?php if($user_choice == 'no'){echo 'selected'; }>NO</option>
<option value="yes" <?php if($user_choice == 'yes'){echo 'selected'; }>YES</option>
</select>
I have 2 php html forms, both consisting of 1 select list. In the first form, I have a select list that asks the user to select their State. According to the state selection on the first page, when the user clicks submit, the second selection list should show the postcodes for that state.
I am having difficulty in performing this task as they 2 select lists are on 2 different pages, i know how to use javascript if they are on the same but i am a bit stumped as they are on different pages. Im not sure how to link them together.
State* <select id="state" name="state"">
<option value="">Select</option>
<option value="OKC">OKC</option>
<option value="NYC">NYC</option>
<option value="CAL">CAL</option>
</select><br />
So if the user selects OKC from first list on the first page, the second list on the second page should show only postcodes for OKC
If you absolutely need to have 2 different PHP pages for your select elements, you could use an HTTP parameter. For example you could have the first form have a submit button which takes you to the second PHP page:
firstpage.php:
<form action="secondpage.php" method="get">
<select id="state" name="state">
<option value="">Select</option>
<option value="OKC">OKC</option>
<option value="NYC">NYC</option>
<option value="CAL">CAL</option>
</select>
<input type="submit" value="Next page" />
</form>
The submit button would take your browser to the secondpage.php but according to your state selection, it would attach a parameter, for example secondpage.php?state=OKC.
On secondpage.php you could use the parameter to your advantage:
$state = $_GET['state'];
Use PHP statements to dynamically generate your <select> element:
<?php
$state = $_GET['state'];
$postcodes = null;
if($state == "NYC")
{
$postcodes = array("postcode1", "postcode2");
}
if($state == "OKC")
{
$postcodes = array("postcode3", "postcode4");
}
?>
<form action="anotherpage.php" method="get">
<select id="postcode" name="postcode">
<?php
foreach ($postcodes as $p)
{
echo '<option value="'.$p.'">'.$p.'</option>';
}
?>
</select>
<input type="submit" value="Next page" />
</form>
Of course there are more efficient ways to go about this, but this should give you an idea.