Jump to content

Select option


jemz

Recommended Posts

How do i set value in my select option, and i want this value is from the database. I tried this but it's not working

<select name="status" value="<?php echo $status; ?>">       <option value=""></option>    <option value="Active">Active</option>    <option value="Inactive">Inactive</option></select>

Can you help me on this.Thank you.

Link to comment
Share on other sites

You set the value by adding selected="selected" to the option that contains the value you want.
Hi,thank you for the quick reply,is this what you mean?
<select name="status" >      <option value="<?php echo $status; ?>" selected="selected"></option>    <option value="Active">Active</option>    <option value="Inactive">Inactive</option></select>

Link to comment
Share on other sites

No, this is what I mean:

<select name="status">    <option value=""></option>    <option value="Active" <?php if($status == 'Active') { echo 'selected="selected"'; } ?>>Active</option>    <option value="Inactive" <?php if($status == 'Inactive') { echo 'selected="selected"'; } ?>>Active</option></select>

  • Like 1
Link to comment
Share on other sites

No, this is what I mean:
<select name="status">	<option value=""></option>	<option value="Active" <?php if($status == 'Active') { echo 'selected="selected"'; } ?>>Active</option>	<option value="Inactive" <?php if($status == 'Inactive') { echo 'selected="selected"'; } ?>>Active</option></select>

Hi sorry for the late reply.Thank you so much it's working.you are very great.
Link to comment
Share on other sites

No, this is what I mean:
<select name="status">	<option value=""></option>	<option value="Active" <?php if($status == 'Active') { echo 'selected="selected"'; } ?>>Active</option>	<option value="Inactive" <?php if($status == 'Inactive') { echo 'selected="selected"'; } ?>>Active</option></select>

 Hi,can you help me please on this i am stuck in this,i could not select the day.Thank you in advance.<select name="day" >	  <?php for($d=1;$d<=31;$d++)    echo '<option     f($day==$d)	    selected='selected'>'.$d.'</option>';						    ?> 								  </select>

Link to comment
Share on other sites

Try
  <?phpfor($d=1;$d<=31;$d++){	echo '<option';	if($day==$d){			echo ' selected="selected"';}  echo '>'.$d.'</option>';}											    ?> 

Hi,it's working where did you learn this kind of coding i mean the way you do in your echo?Thank you so much it helps me.
Link to comment
Share on other sites

Done this kind of think many times with select and option elements before, not exactly like this, but similar.
Is it possible also in this select example inside the select option cat orchid mouse Karl Jupiter if the user will select the cat it will display to the texfield "Animal" and if the user will select Ochid it will Display to the textfield "plant" is this possible?
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...