Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > HTML / XHTML
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 10-31-2009, 05:54 AM
  #1
Curver
Novice (Level 1)
 
Join Date: Oct 2009
Posts: 2
iTrader: (0)
Curver is an unknown quantity at this point
Simple Problem: Drop Down Box - How?

Hello i have a simple problem, i am wanting to make a drop down box which selects a value automatically:

<select size="1" name="decision" value="<?php if(isset($results[0]['decision'])){ echo validHTML($results[0]['decision']);} ?>">
<option selected value="">-</option>
<option value="1">Yes</option>
<option value="0">No</option>
</select>

As you can see, the drop box options are fixed but i want it to select the value which has already been selected by the user in the database but it seams the value attribute dosnt work.

How do you do this?

Thanks,
Curver
Curver is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-31-2009, 07:42 AM
  #2
batterj2
Soldier (Level 11)
 
batterj2's Avatar
 
Join Date: Jan 2005
Location: Sheffield
Posts: 132
iTrader: (0)
batterj2 is on a distinguished road
The select tag doesn't make use of the value attribute so remove it.

In your code you have selected the value, the first one in fact. You need to do your test for selection for each option i.e.

PHP Code:
<select name="decision">
<option <?php echo (isset($results[0]['decision']) && $results[0]['decision'] == 'selected="selected" ' '');?>value="1">Yes</option>
<option <?php echo (isset($results[0]['decision']) && $results[0]['decision'] == 'selected="selected" ' '');?>value="0">No</option>
</select>
On another note, you shouldn't leave the option of "blank" to the user unless the blank option is a viable option - in this case, where the answers should only be Yes or No, this wouldn't be correct.
__________________
James Battersby BSc. (Hons) Artificial Intelligence, www.jamesbattersby.com
Professional Member of the British Computer Society (2005 onwards), ISEB Foundation Certificate in Software Testing (2007)
XHTML, CSS, Javascript, PHP, MySQL, MSSQL, Oracle, Java (J2SE, J2EE (Struts, Spring)), C#, Jasc Paint Shop Pro, Adobe Photoshop, GIMP, Software Testing
batterj2 is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-31-2009, 08:12 AM
  #3
Curver
Novice (Level 1)
 
Join Date: Oct 2009
Posts: 2
iTrader: (0)
Curver is an unknown quantity at this point
Thank you for your help.

I have since found a solution:
HTML Code:
<!--webbot bot="Validation" b-disallow-first-item="TRUE" --><select size="1" name="decision">
		<option value="">-</option>
		<option value="1">Yes</option>
		<option value="0">No</option>
		</select>
</td>
		<script type="text/javascript">
		document.form1.decision.value = <?php if(isset($results[0]['decision'])){ echo validHTML($results[0]['decision']);} ?>;
		</script>
The reason i left a blank field is that i didnt want users to be lazy and no select an option. It is not as simple as "have you read our terms yes/no" where it can default to no. This is somthing which can be either a yes or a no option and the user must be promped to make a selection.
Curver is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart
 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 03:54 AM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.