Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

HTML Forum


You are currently viewing our HTML Forum as a guest. Please register to participate.
Login



Post a Project »

Find a Professional HTML Freelancer!

Find a Freelancer to help you with your HTML projects

FREE Outsourcing eBook!

Reply
How do I assign a value to a combo box?
Old 11-25-2005, 12:01 AM How do I assign a value to a combo box?
Webmaster Talker

Posts: 626
Trades: 0
I have created a database using mysql & php. However, I have run in to a road block... I want to create an edit screen, where the "addclient" form will open and populates each element's value with the mysql variables.

I can populate the text fields without a problem but how do I change the value of radio buttons and combo boxes.

Here is what I have... Which doesn't work.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
	How is your mood?
	<select name="Mood">
				<option>Happy</option>
				<option>Sad</option>
				<option>Neutral</option>
			</select>
	<script type="text/javascript" language="javascript">
		document.getElementById("Mood").value = "Sad";
	</script>
</body>
</html>
Can anyone help me?

Zinc.
jim.thornton is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-25-2005, 12:48 AM
RoLLiNLoW54's Avatar
Super Talker

Posts: 116
Location: Canandaigua, NY
Trades: 0
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
	How is your mood?
	<select name="Mood">

<?php

$db = mysql_connect("yourDbHost", "yourDbUser", "yourDbPass");
mysql_select_db("yourDbName",$db);

result = mysql_query("SELECT * FROM someTable",$db);

if ($myrow = mysql_fetch_array($result))
     do {
          print("<option name=\"$myrow[value]\" value=\"$myrow[value]\">$myrow[value]</option>");
          }
     while ($myrow = mysql_fetch_array($result));
}

?>

	</select>
	<script type="text/javascript" language="javascript">
		document.getElementById("Mood").value = "Sad";
	</script>
</body>
</html>
something like this?
__________________

Please login or register to view this content. Registration is FREE
: A distinguished web presence begins with distinguished web developers.
RoLLiNLoW54 is offline
Reply With Quote
View Public Profile Visit RoLLiNLoW54's homepage!
 
Old 11-25-2005, 02:54 AM
eburza's Avatar
Super Talker

Posts: 122
Name: Antonio Magdic
Location: Zagreb, Croatia
Trades: 0
you don't need name=\"$myrow[value]\" under <option> tag!



Quote:
Originally Posted by RoLLiNLoW54
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
	How is your mood?
	<select name="Mood">

<?php

$db = mysql_connect("yourDbHost", "yourDbUser", "yourDbPass");
mysql_select_db("yourDbName",$db);

result = mysql_query("SELECT * FROM someTable",$db);

if ($myrow = mysql_fetch_array($result))
     do {
          print("<option name=\"$myrow[value]\" value=\"$myrow[value]\">$myrow[value]</option>");
          }
     while ($myrow = mysql_fetch_array($result));
}

?>

	</select>
	<script type="text/javascript" language="javascript">
		document.getElementById("Mood").value = "Sad";
	</script>
</body>
</html>
something like this?
__________________

Please login or register to view this content. Registration is FREE
eburza is offline
Reply With Quote
View Public Profile Visit eburza's homepage!
 
Old 11-25-2005, 02:00 PM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
Quote:
Originally Posted by zincoxide

I can populate the text fields without a problem but how do I change the value of radio buttons and combo boxes.

.
Zinc, to mark any option within a combo box as being the current value, give it a selected="selected" attribute. For example, say you wanted "Sad" to be the selected value,

HTML Code:
<option selected="selected">Sad</option>
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 11-25-2005, 02:01 PM
RoLLiNLoW54's Avatar
Super Talker

Posts: 116
Location: Canandaigua, NY
Trades: 0
whoop, sorry bout the name thing
__________________

Please login or register to view this content. Registration is FREE
: A distinguished web presence begins with distinguished web developers.
RoLLiNLoW54 is offline
Reply With Quote
View Public Profile Visit RoLLiNLoW54's homepage!
 
Old 11-25-2005, 04:45 PM
TrentonD's Avatar
Ultra Talker

Posts: 253
Location: Calgary, Alberta, Canada
Trades: 0
Quote:
Originally Posted by Kyrnt
Zinc, to mark any option within a combo box as being the current value, give it a selected="selected" attribute. For example, say you wanted "Sad" to be the selected value,

HTML Code:
<option selected="selected">Sad</option>
Yea, but if you want to show something that has been submitted by a form, you should use this code, in PHP of course:

PHP Code:
<option value="0" <?php if($ql_category == 0){ echo "SELECTED"; }?>>Option 1
<option value="1" <?php if($ql_category == 1){ echo "SELECTED"; }?>>Option 2
But of course, you will need to post the variables to this page, and also set them as variables.
__________________
Signature Coming Soon! :)
Please login or register to view this content. Registration is FREE
TrentonD is offline
Reply With Quote
View Public Profile Visit TrentonD's homepage!
 
Old 11-26-2005, 01:59 PM
eburza's Avatar
Super Talker

Posts: 122
Name: Antonio Magdic
Location: Zagreb, Croatia
Trades: 0
just a tip ....

if u using xhtml use selected="selected" instead of SELECTED ...
__________________

Please login or register to view this content. Registration is FREE
eburza is offline
Reply With Quote
View Public Profile Visit eburza's homepage!
 
Old 12-06-2005, 10:35 PM
Webmaster Talker

Posts: 626
Trades: 0
Thank you for your help.
jim.thornton is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How do I assign a value to a combo box?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.26589 seconds with 12 queries