I need to populate dropdown with data from mysql database, i do that with this code
Maker: <br>
<select name="maker" >
<?php
$sql="select name from makers";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query)){
?>
<option value="<?php echo $row["name"] ?>"><?php echo $row["name"] ?></option>
<?php
}
?>
</select>
<br>
And now i need to change the design and make it little nicer using bootstrap dropdown, but i don't know how to connect this code with bootstrap code for dropdown
To use the bootstrap-styled selects, just add the form-control class to your <select>:
<select name="maker" class="form-control" >
Related
on calculatePC.php, I have this code to display the finish_product
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/>
Let's say I have chosen Table as the finish_product.
On docalculate.php, I would like to display what I've chosen based on the dropdown list I've selected.
I tried this but there is error.
<?php echo $_POST['finish_product'] ?>
May I know how to display the result?
This doesn't exist:
$_POST['finish_product']
because you don't have a form element named "finish_product" in your markup. Add that name to the form element:
<select name="finish_product" class="itemTypes">
You need to do two things:-
Create a form before select and give it an action
give name attribute to your select box, then only you can get data in $_POST
So do like below:-
<form method="POST" action = "docalculate.php"> // give the php file paht in action
<select class="itemTypes" name="finish_product"> // give name attribute to your select box
<?php while ($row1 = mysqli_fetch_array($result)) { ?>
<option value="<?php echo $row1['finish_product']; ?>">
<?php echo $row1['finish_product']; ?>
</option>
<?php } ?></select>
<br/><br/>
<input type ="submit" name="submit" value ="Submit">
</form>
Now on docalculate.php:-
<?php
echo "<pre/>";print_r($_POST['finish_product']); // to see value comes or not
Note:- through Jquery its also possible. Thanks
I have texbox and dropdown list which is populated from mysql database.I want to change textbox value using dropdown list, without refreshing the page.
Here is my code and Thanks in Advance.
<select name="select" id="dropdownlist1">
<option id="0">-- Select the Company --</option>
<?php
require("dbcon.php");
$getallcompanies = mysql_query("SELECT * FROM ifcandetails6");
while($viewallcompanies = mysql_fetch_array($getallcompanies)){
?>
<option id="<?php echo $viewallcompanies['tcuid']; ?>"><?php echo $viewallcompanies['tcname'] ?></option>
<?php
}
?>
</select>
Here is my Input field code:
<input type="text" id="field1" value="<?php echo $viewallcompanies['tcname']?>" disabled/>
Use following
$(document).ready(function(){
$("#dropdownlist1").change(function(){
$("#field1").val($(this).val());
});
});
As you can do it on front side itself, you dont need to change in your PHP code. Add the following code on DOM ready.
<?php
$sql="select software from software_table";
$qry=mysql_query($sql);
$count=mysql_num_rows($qry);
$row=mysql_fetch_array($qry);
$data=['software_name'];
?>
<?php
for($i=0; $i<=count($data); $i++){
?>
<select name="software_name">
<option vale="<?php echo $data[$i]?>">$data</option>
}
?>
`I dont know if this is possible, but what I want to happen is that, when I add new software from software_table. My drop-down menu for software will get its option value from the database to become updated. I am thinking to use For-Loop for this, but I dont know how to start or is it really possible.
example.
in my drop-down menu. i have 3 option value.
1.MS OFFICE
2.AUTODESK
3.PRIMAVERA
and then I add another software from the database which is WINDOWS 8.
I want my drop-down menu to have those 4 value.
Try to use the following code -
$sql="select software from software_table";
$qry=mysql_query($sql); ?>
<select name="software_name">
<?php while($row=mysql_fetch_array($qry)) {
$data=$row['software_name']; ?>
<option vale="<?php echo $data; ?>"><?php echo $data; ?></option>
<?php }
?>
</select>
<select name="software_name">
<?php
$sql="select software from software_table";
$qry=mysql_query($sql);
while ($row=mysql_fetch_array($qry))
{
// In your case, each row contains only one value: $row[0] = the value of software field
echo "<option vale=\"$row[0]\">$row[0]</option>";
}
?>
</select>
This will generate the HTML code as:
<select name="software_name">
<option vale="MS OFFICE">MS OFFICE</option>
<option vale="AUTODESK">AUTODESK</option>
<option vale="PRIMAVERA">PRIMAVERA</option>
</select>
I have two dropdowns .i want second dropdown list shoul changed according to the value selected in first dropdown.
this is my first dropdown
Category :<select name="Category" id="a1_txtBox5" required="required">
<option value="select">select..</option>
<?php while($selectcategoryarray=mysql_fetch_array($selectcategory)) {
?>
<option value="<?php echo $selectcategoryarray[1];?>"><?php echo $selectcategoryarray[1];?></option>
<?php
}
?>
</select>
And here is my second dropdown:
<label style="margin-left:24px;">Subcategory :</label><select style="margin-right:35px;" name="subcategory" id="a1_txtBox3" required="required">
<option value="select"> select..</option>
<?php while($selectsubcategoryarray=mysql_fetch_array($selectsubcategory)) {
?>
<option value="<?php echo $selectsubcategoryarray[2];?>"><?php echo $selectsubcategoryarray[2];?></option>
<?php
}
?>
</select>
Please help.
Exactly you need to handle the Change Event for your first Select element and in the body of the event you need to send request to server for getting data of second Select element.
I recommend to use an ajax process to doing this.
And o this you should use jQuery for handling events and have ajax.
I am new in this forum..Forgive me for any kind of mistake & help me.
I have a form with only two fields,first one textfield & next dropdown list.Now I want to show value in list from database based on textfield value from database.i.e If I type perfect username it will show me in dropdown the corresponding emailid(s) of that user.It will change after the username being changed.
Hope someone will help me in this matter.I was working a long time,but cant satisfied.Thanks in advance.This is the code what I have tried.But I want just the reverse.
`
function CBtoTB()
{document.getElementById("username").value=document.getElementById("usernameselect").value}
<?php
$result=mysql_query("select Username from users");
$options="";
while ($row=mysql_fetch_array($result)) {
$username=$row["Username"];
$options.="<OPTION VALUE=\"$username\">".$username.'</option>';
}
?>
<select name="usernameselect" id="usernameselect" onchange="CBtoTB()">
<option value="">< select user ><?php echo $options ?></option>
</select>
<input name="username" type="text" id="username" value="<?php echo $username ?>" size="25" readonly="readonly" />`
You option was writen wrongly please try this :
<select name="usernameselect" id="usernameselect" onchange="CBtoTB()">
<option value="">< select user ></option>
<?php echo $options ?>
</select>