473,830 Members | 2,031 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The <select> tag doesn't support a value option

18 New Member
I have a PHP/mySQL database running, and I've realized I'm come across an awkward little bug.

I have a form where a user fills out their information using populated drop down boxes. This information gets stored in the database. Then, if a user wants to edit their information later, they can go to the Edit Details page which calls up a page almost identical to the original form when they first set themselves up. Of course, the person's information is pulled from the database, and is echoed as the values of the form elements.

My issue is that the drop down boxes do not echo the value They are updated in the database correctly, but the drop downs don't know how to select the appropriate values.

The <select> tag doesn't support a value option, and I can't hardcode the selected="selec ted" into any specific <option> tag because the input from the database needs to determine which one that is.

Any suggestions anyone has would be greatly appreciated. Thanks!
Jun 28 '07 #1
8 2747
sumaabey
29 New Member
Try this
Expand|Select|Wrap|Line Numbers
  1. <?
  2. $sql="select name from table name";
  3. execute the query
  4. $row=mysql_fetch_array($res);
  5. ?>
  6. <select>
  7. <option value="<?=$row['name']?>" selected></option>
  8. </select>
Jun 28 '07 #2
nathj
938 Recognized Expert Contributor
Try this
<?
$sql="select name from table name";
execute the query
$row=mysql_fetc h_array($res);
?>
<select>
<option value="<?=$row['name']?>" selected></option>
</select>
Alternatively you can use selected="selec ted" in the option tag of the select element. This works just fine.

So as you build up the select using your database you can add this line to the item that is stored against the user.

Cheers
nathj
Jun 28 '07 #3
pbmods
5,821 Recognized Expert Expert
Heya, dkate.

Expand|Select|Wrap|Line Numbers
  1. foreach($dbresults as $row => $data)
  2.     echo "<option value=\"{$data['rowid']}\"" . (($data['rowid'] === $selectedValue)
  3.         ? ' selected="selected"'
  4.         : ''
  5.     ) . ">{$data['rowname']}</option>\n";
  6.  
If that is not an option, you could add some JavaScript somewhere after you create the SELECT element that runs through the options for your SELECT and sets the selected property to true if its value matches.
Jun 28 '07 #4
dkate777
18 New Member
Thanks All

I run the test and i see it's selected the right value, but still not display it.
Is anybody know why it's display?
Jun 28 '07 #5
pbmods
5,821 Recognized Expert Expert
Heya dkate.

I run the test and i see it's selected the right value, but still not display it.
Is anybody know why it's display?
Please elaborate. What do you mean by 'selected the right value', and 'still not display it'?
Jun 28 '07 #6
Motoma
3,237 Recognized Expert Specialist
Thanks All

I run the test and i see it's selected the right value, but still not display it.
Is anybody know why it's display?
Perhaps you could post the relevant code?
Jun 28 '07 #7
dkate777
18 New Member
OK, I know where is my problem is.
I use jave script to display value on this form from other form
document.form.f ieldname.value= firstformValue

i can display this value on textbox, but not on select box. I think it's possible, but i don't know how to do this.
Is anybody know how to pass value the right way
Jun 28 '07 #8
Purple
404 Recognized Expert Contributor
Hi dkate777,

you need to build the select statement with all of the options as you do on the initial form and append selected="selec ted"

take a look at the following function:

[PHP]//*
//* function - displays the job cost codes
//*
function job_cost_cat_se lect($data)
{
$code_select = "<tr><td>Co st type :</td><td><select name=\"jcexp_co de\">
<option value=\"0\" selected=\"sele cted\">Not selected</option>";
$rows = 0;
$count = count($data);
while($rows < $count)
{
if(isset($data[$rows][0])) $code_select = $code_select . "<option value=\"" .
rtrim($data[$rows][0]) . "\">" . rtrim($data[$rows][1]) . "</option>";
$rows++;
}
$code_select = $code_select . "</select></td></tr>";
if (isset($_POST['jcexp_code']))
{
$code_select = str_replace("<o ption value=\"".$_POS T['jcexp_code']."\">",
"<option value=\"".$_POS T['jcexp_code']."\" selected=\"sele cted\">",$code_ select);
$code_select = str_replace("<o ption value=\"0\" selected=\"sele cted\">",
"<option value=\"0\">",$ code_select);
}

return($code_se lect);
}[/PHP]

Hope this helps

Regards Purple
Jun 28 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1592
by: Dennis M. Marks | last post by:
I have a problem with the following code. It generates a <FORM><SELECT><OPTION> list. There is no problem in the generating. The problem is in the execution as follows. It works fine in Mac IE with and without the <FORM></FORM>. In Mac Netscape 6 the onChange does not activate if there is no <FORM></FORM>. When I put it in a form as indicated below the value of train.options.value is undefined. What am I doing wrong?
2
1737
by: abs | last post by:
Hello everybody. A piece of html code: <form ... > <select ....> <option .... <option .... </select> <select ....>
0
2236
by: rayone | last post by:
Hi folks. I need advice. 2 options, which do you think is the better option to display/retrieve/report on the data. Keep in mind reporting (Crystal), SQL Performance, VB Code, usability, architecture. Case 1: On a web page I would like to render a dropdown list
6
13034
by: Chris Fink | last post by:
Does anyone know it is possible to include a small image(.gif .jpeg) within a <SELECT><option> so that the user would see the option text as well as a little image(icon) in the option? I know this is not an ASP.NET related question, but I know this group is knowledgeable and quick with responses. Thanks
3
14332
by: i_dvlp | last post by:
I'm trying to replicate a fancy drop-down control (MS-egads!) with form <select><option> It doesn't look like you can specity width as an attribute or define width with CSS. It looks like my choices are to use smaller fonts or choose shorter option strings. inline: I want to put a small graphic immediately to the right of the select.
3
2992
by: veg_all | last post by:
Say I have: <select> <option value='a' > First <option value='b' > Second <option value='c' > Third </select> Is there a way I can access the values First, Second and Third from an array ? I want to write a javascript function that can
5
8745
by: Isha | last post by:
Hi all, I wanted to change the background color for only the first option in a select box, but following changed the background color for the whole dropdown box. <select name="alltags" class="select" style="background:yellow"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option>
2
3051
by: msg2ajay | last post by:
hi all, I have a problem with <html:select> i am getting a value from the database but it is not setting to my <select value>. Can any bady tellme what is the problem. My code is given below.. <html:select property="conttitle" styleClass="dropdown" value="${conttitle}"> <html:option value="1">1 - Mr</html:option> <html:option value="2">2 - Ms</html:option> </html:select>
1
2374
by: volynetsv | last post by:
Hello. I have a small problem, here's code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>iframe popup (JS)</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body>
4
6101
by: html | last post by:
Hello all, I need to change the colour of my text. For the paragraph I do document.fgColor ="blue" ; but how do I do this for the select tags? ....and I prefer it to apply to all select tags Tia.
0
9786
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9641
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10479
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10523
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10199
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7741
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5616
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4409
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3073
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.