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>
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
" >
" >
" >
*
<select name="sample" class="form-control" id='select'>
<?php
$sam1="attingal"; $sam2="kollam";
$getstd="SELECT stdid,firstname,lastname FROM student WHERE centre='$sam1' AND centre='$sam2' ORDER BY firstname ASC";
$qs=$conn->query($getstd);
$qs->setFetchMode(PDO::FETCH_NUM);
while($getstd=$qs->fetch()) {
?>
<option value='<?php echo $getstd[0]; ?>'>
<?php echo $getstd[1]." ".$getstd[2]; ?>
</option>
<?php } ?>
</select>
Nothing is displaying when I run the above code
Your problem is here:
WHERE centre='$sam1' AND centre='$sam2'
That condition can never be true. a field can't hold 2 different values at once.
You supposedly wanted OR, so change it to
WHERE centre='$sam1' OR centre='$sam2'
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.
Any help would be greatly appreciated!!
I am building a php form to update a MySQL database linked to my website.
Part of my form includes list fields where the user can hold ctrl to select multiple values and these are then passed into one MySQL field as comma separated values. See below for three real examples of the data:
3014
3014,3015,3026
3026,3028
The form is updating my database as required, however when the user goes back in to the form to do another update the multiple values they chose aren't pre-selected.
Can anyone help me to figure out why $row_editme['NewsTypeID'] is the field containing the string of values. The field type is a SET.
<td nowrap="nowrap" align="right">NewsTypeID:</td>
<td>
<select name="NewsTypeID[]" size="4" multiple="multiple">
<?php
do {
?>
<option value="<?php echo $row_types['id']?>" <?php if (!(strcmp($row_types['id'], htmlentities($row_editme['NewsTypeID'], ENT_COMPAT, 'utf-8')))) {echo "SELECTED";} ?>><?php echo $row_types['name']?></option>
<?php } while ($row_types = mysql_fetch_assoc($types)); ?>
</select>
</td>
Try something like this,
<select name="NewsTypeID[]" size="4" multiple="multiple">
<?php
do {
$selected = htmlentities($row_editme['NewsTypeID'], ENT_COMPAT, 'utf-8');
$selected_arr = explode(",",$selected);
?>
<option value="<?php echo $row_types['id']?>" <?php if (in_array($row_types['id'],$selected_arr)) {echo "selected";} ?>>
<?php echo $row_types['name']?>
</option>
<?php } while ($row_types = mysql_fetch_assoc($types)); ?>
</select>
I think it is not supposed to be selected.
Can you try checked?
<input type="checkbox" <?php /*if condition is met here, then*/ echo "checked='checked'" ?> />
It will pre-select all the values the user selected.