I would like to display the result which I have selected based on the drop down list. This is my drop down list code which is retrieved from the finish_product under bom table (calculate.php)
<tr>
Select product:
<select class="itemTypes">
<?php
while ($row1 = mysqli_fetch_array($result)) {
?>
<option value="<?php echo $row1['finish_product']; ?>">
<?php echo $row1['finish_product']; ?>
</option>
<?php } ?></select>
<br/><br/>
</tr>
For example, under the drop down list I selected 'Table', how do I display the result in doCalculate.php?
Right now I just hard code Table which is not feasible. Anyone to help me out?
There are many, many ways which you could accomplish your goal. I would suggest using a JavaSctipt "onchange" event, detect the selected option, and then update the DOM with its contents.
Related
I need to post the value from the drop down, in which the dropdown contains items which are retrieved from the database. To display the item of the table I use echo in the option. But then, I need to get that value of item selected to be updated in the database. As be seen below, I've tried the code which (surely) will not work. How is it possible to get the the value of selected item?
Your suggestion will be appreciated.
Thank you.
<select name="user" class="form-control" id="user">
<?php while ($hasil = mysqli_fetch_array($result2)){ ?>
<option name="user_name"><?php echo $hasil['user_name'] ?></option>
<option name="user_name" value="<?php echo $hasil['user_name'] ?>" hidden></option><?php }?>
</select>
<select name="user" class="form-control" id="user">
<?php while ($hasil = mysqli_fetch_array($result2)){ ?>
<option><?php echo $hasil['user_name'] ?></option>
<?php } ?>
</select>
This code solves your problem, Check at your side and let me know in case of any issue.
We need to give name only once in select tag and no need to add a extra option only for value.
You must fill your dropdown from base table after that you must check value or id from second table that stored in database. If id or value is equal you must set selected='selected' in your option element
Hope it is help you to resolve you problem
" >
" >
" >
*
I am trying to get a dropdown list to populate. I have two tables, a registration table and a studentclasses table. I am looking to populate the dropdown list from the class table, as a field entry in the registration table. My code is as follows:
<p>Class: <select name="classID">
<?php $classlist_sql="SELECT * FROM studentclasses";
$classlist_qry=mysqli_query($dbconnect, $classlist_sql);
$classlist_rs=mysqli_fetch_assoc($classlist_qry);
do { ?>
<option value="<?php echo $classlist_rs['classID']; ?>"
<?php
if($classlist_rs['classID']==$_SESSION['signuptest']['classID']) {
echo "selected=selected";
}
?>
><?php echo $classlist_rs['classcode']; ?></option>
<?php } while ($classlist_rs=mysqli_fetch_assoc($classlist_qry));
?></select>
</p>
My Studentclasses table has the fields classID and classcode, and I am wanting the classcode to appear in the drop down.
Any help would be greatly appreciated.
i need to populate another drop down based on previous selected drop down. please help.My code is below. Now, how i pass the previous selected value to next dropdown where clause?
<td align="right">Country</td>
<td>
<select type="text" name="Country">
<option selected value="">Country Code</option>
<?php $result=mysql_query("SELECT CountryName FROM tbl_country");
while($row_result=mysql_fetch_row($result))
{ echo "<option value=\"$row_result[0]\">$row_result[1]</option>";}
?>
</select>*
</td>
<td align="right">Area</td>
<td>
<select type="text" name="Area">
<option selected value="">Area</option>
<?php $result=mysql_query("select Area from tbl_area where CountryName='???'");
while($row_result=mysql_fetch_row($result))
{ echo "<option value=\"$row_result[0]\">$row_result[0]</option>";}
?>
</select>*
</td>
How can i set the selected country name into the second queries where clause?
Thanks in advance.
As PHP is run on the server you will need to request the server to run the second query for you by either having the page refresh or do it via AJAX so that the page refreshes but without looking like it has.
The easiest solution would be to do it across 2 pages, if you want to do it on the one then AJAX is the way forward.
Give me a minute and i'll look for an example.
Disclaimer: It's been a while since I last wrote any code. The quality of my code is likely to be sub-par. You've been warned.
Greetings.
I am coding a basic form that uses a SELECT list I populate from my database.
However, my user needs the form to be dynamic and wants to be able to select either MasterTable1 or MasterTable2 or MasterTable3...
Instead of hardcoding the table name for the database query that populates the SELECT list, I attempted to implement a basic Ajax action (used example from w3schools)...and that's when I lost my sanity...
I can output <div id='txtHint'></div> in my page and it shows the correct table name that was picked.
But how do I pass the correct table name to my query that will populate my SELECT list???
I tried
<select name="DBFilename" id="DBFilename" size="0">
<option value="">Select Filename</option>
<?php
$sql="select distinct filename from "."<div id='txtHint'></div>";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)){ ?>
<option value="<?php echo $row['filename']; ?>"><?php echo $row['filename']; ?></option>
<?php } ?>
</select>
But to no avail. This is confusing since I can do this...
...
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","gettable.php?q="+str,true);
xmlhttp.send();
}
</script></head>
<body><form><select name="SrcTbl" id="SrcTbl" size="0" onchange="showTable(this.value)">
<option value="">Select Data Table</option>
<option value=""> </option>
<option value="MasterTable1">up to 31 days old</option>
<option value="MasterTable2">62 days old</option>
</select>
</form><br /><div id="txtHint"><select name="tabList"><option></option></select> </div>
</body></html>
And the name of my table will be displayed in the SELECT list 'tablist'.
How do I pass the correct table name to my query that will populate my SELECT list? Thanks!!
(Pastebin =>form code)
m8, ajax is mainly used for user experience and populating a select list is so easy mode that it shouldnt be bothered with ajax in the first place!
You should use ajax if you want to use some methods on user submitted data and create an illusion of seamless data exchange between the server and the client, and based on the return results render a corresponding view or an element of the view.
unless you load every element of the view with ajax, you should populate your html with php from the start!
<select name="DBFilename" id="DBFilename" size="whatever since style belongs to css">
<option selected="selected">Select Filename</option>
<?php
$sql="SELECT DISTINCT filename from 'wherever'";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)){ ?>
<option value="<?php echo $row['filename']; ?>"><?php echo $row['filename'];?>
</option>
<?php } ?>
</select>
Create a separate php script which returns a list of select options -> values depending on the table name given to it. You must remember to protect against sql injection. Then use ajax to retrieve the list and insert it into the select.
I am creating a form where the users will have to select the country from the drop down list. as soon as they selects it should activate another drop down list where it should show the states belonging to the country and hence it should process the value from country Id of element. and as soon as the user selects the states another drop down list should activate listing the cities belonging to that particular states, and hence so on to areas.
for that i have written the php and html code like this.
Select Countries : <select name="countries"><br/>
<?php
foreach($property->getAllCountries() as $countries)
{
?>
<option value="<?php echo $countries['id']; ?>"><?php echo $countries['name']; ?></option>
<? } ?>
</select><br/>
Select State : <select name="state">
<?php
foreach($property->getStatesFromCountryId($countryId) as $states)
{
?>
<option value="<?php echo $states['id']; ?>"><?php echo $states['name']; ?></option>
<? } ?>
</select>
the javascript should automatically insert $countryId from and populate the states after the user selects it.
i am noob at javascript i would appreciate if someone could guide me how to achieve this?
thank you.
sorry for bad english.
you should add onchange="showstates()" to select countries and a div to add states of country to it
function showstates()
{
var country=document.getElemtById("countries").value;
if (country=="anywhere")
{
document.getElemtById("statesofcountries").innerHTML='<div>"states list"</div>';
}
}
check this link
You can always google it up:
http://roshanbh.com.np/2007/12/change-dropdown-list-options-values-from-database-with-ajax-and-php.html