0

HI

I have a drop down box after selecting it page must be refreshed and it must show the selected value.

How to do it

example I select one item in a dropdown and page must be refresh and show the selected value in drop down after refresh?

thanks

3
Contributors
8
Replies
13
Views
5 Years
Discussion Span
Last Post by diafol
0

javascript submit

php to reselect the value in the dropdown

0

javascript submit

php to reselect the value in the dropdown

I didnt got you

i have no button .

0

Use the onchange attribute torun a .submit

0

Use the onchange attribute torun a .submit

My code

<select name="item" onchange="this.form.submit();" >
<?php

$data = @mysql_query("select * from Item");
$array = array();
while ($row = mysql_fetch_assoc($data))
{
$id = $row;
$Itemname= $row;
echo '<option value='.$id.'>'.$Itemname.'</option>'."\n";
}
?>
</select>

Problem -

page is refreshing but not showing selected value in drop down box.

0

You need to get the selected value from $_POST or $_GET depending on your form method attribute.

0
<SCRIPT LANGUAGE="javascript">
function update_post()
{
document.frm.submit();
}
</SCRIPT>
 
<select id="productid" name="productid" onChange="update_post();">
<?php
$sql_all ="select * from product";
$qry_selectall=mysql_query($sql_all);
while($res_selectall=mysql_fetch_array($qry_selectall))
{
$content_all=$res_selectall['id'];
$code = $res_selectall['page_title'];
?>
<option id="prodid" value="<?php echo $content_all;?>" <?php if($content_all==$page_id) echo 'selected' ?> ><?php echo $code;?></option>
<?php
}
?>
</select>
0
<SCRIPT LANGUAGE="javascript">
function update_post()
{
document.frm.submit();
}
</SCRIPT>
 
<select id="productid" name="productid" onChange="update_post();">
<?php
$sql_all ="select * from product";
$qry_selectall=mysql_query($sql_all);
while($res_selectall=mysql_fetch_array($qry_selectall))
{
$content_all=$res_selectall['id'];
$code = $res_selectall['page_title'];
?>
<option id="prodid" value="<?php echo $content_all;?>" <?php if($content_all==$page_id) echo 'selected' ?> ><?php echo $code;?></option>
<?php
}
?>
</select>

i tried but not working...

<?php
$sql_all ="select * from Item ";
$qry_selectall=mysql_query($sql_all);
while($res_selectall=mysql_fetch_array($qry_selectall))
{
$id=$res_selectall['Item_id'];
$Itemname = $res_selectall['Item_name'];
?>

<option id="itemid" value="<?php echo $id;?>" <?php if($id==$page) echo 'selected' ?> ><?php echo $Itemname;?></option>  
 <?php }
?>
 </select>

Page refresh but not retaining select value.

my page - http://web.nmsu.edu/~madhira/Project/Edititem.php

Here you try by selecting books.

Thank you

0
<?php
$data = @mysql_query("select * from Item");
$array = array();
$options="";  
while ($row = mysql_fetch_assoc($data)){
   $id = $row['Item_id'];
   $Itemname= $row['Item_name'];
   $sel = (isset($_POST['item']) && intval($_POST['item']) == $id) ? ' selected="selected"' : ''; 
   $options .= "<option value=\"$id\"$sel>$Itemname</option>\n";
}
?>
<form method="post">
  <select name="item" onchange="this.form.submit();" >
    <?php echo $options;?>
  </select>
</form>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.