473,544 Members | 1,787 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can JS show the list of choices in drop-down fields?

40 New Member
Background:
I have an PHP form that inserts data into a MySQL DB, and it works. [HTML] Severity of Incident:
<select name="severity" size="1">
<option value="">Select a Severity Option</option>
<option value="Level1 - No Obvious Harm">Level 1 - No Obvious Harm</option>
<option value="Level2 - Non-permanent Harm">Level 2 - Non-permanent Harm</option>
<option value="Level3 - Semi-permanent Harm">Level 3 - Semi-permanent Harm</option>
<option value="Level4 - Major Permanent Harm">Level 4 - Major Permanent Harm</option>
<option value="Level5 - Death">Level 5 - Death</option>
</select>[/HTML]
I have a PHP page that selects the data and displays it, and it works. [PHP]
$db = mysql_connect(" myhost", "mylogon", "mypw"); mysql_select_db ("mydb",$db) ;
$result = mysql_query("SE LECT * FROM mytbl WHERE incident_id = '$_GET[id]'",$db);

$ID = $_GET['id'];
while ($myrow = mysql_fetch_arr ay($result))
{
$sev=$myrow["severity"];[/PHP]
I have a PHP page that allows the user to open the data and update the fields, and I hope there is some Javascript that can help me with this piece.
[PHP]echo "<option value = ".$sev.">".$sev ."</option>"; ?>
<option value="Level1 - No Obvious Harm">Level 1 - No Obvious Harm</option>
<option value="Level2 - Non-permanent Harm">Level 2 - Non-permanent Harm</option>
<option value="Level3 - Semi-permanent Harm">Level 3 - Semi-permanent Harm</option>
<option value="Level4 - Major Permanent Harm">Level 4 - Major Permanent Harm</option>
<option value="Level5 - Death">Level 5 - Death</option>
</select>[/PHP]
The issue I have is twofold, both involving drop-down text fields:
1) The selected data gets displayed in addition to the allowable choices, resulting in two items in the list that are identical

These are the allowed choices:
Level1 - No Obvious Harm
Level2 - Non-permanent Harm
Level3 - Semi-permanent Harm
Level4 - Major Permanent Harm
Level5 - Death
If $sev is 'Level2 - Non-permanent Harm' then when I open the page to update the data, the list shows:
Level2 - Non-permanent Harm
Level1 - No Obvious Harm
Level2 - Non-permanent Harm
Level3 - Semi-permanent Harm
Level4 - Major Permanent Harm
Level5 - Death

2) When I open this page and make a change anywhere and submit, all drop-down text fields that are from the original select are truncated at the first space encountered.

If I keep the $sev value as opposed to selecting a new value, the data that gets passed to the DB is:
Level2 (truncated after that space).

I've been banging my head around within PHP, and I am hoping there are some Javascript tricks I might use.

I need the user to see what exists currently in the data and I need them to see the available choices to use when changing the data, and I need the data to go into the DB on the update without truncating.

This page needs to have data that is user friendly, so I need the phrase 'Level2 - non-permament Harm' rather than 'Level2.' There are about 15 drop-down fields in this form that get truncated on the update.

This is a very newbie question - I have used js only for simple form validation at this point.

TIA,

jej1216
Sep 9 '08 #1
1 1509
acoder
16,027 Recognized Expert Moderator MVP
This may be more of a PHP question. Instead of echoing the selected data, set the option that matches that value to "selected". For the second problem, how do you make changes?
Sep 10 '08 #2

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

Similar topics

2
2362
by: Jefferis NoSpamme | last post by:
Hi folks, Trying to fill in a gap in my understanding of php, and so this is rather newbish: I have created a form where a user selects 2 items from a list of 8 values. That form field is called "choices" and returns a value to the php file as $choices. This form posed no problem when I only allowed a single item to be selected, but...
7
4808
by: Chris Ritchey | last post by:
Hmmm I might scare people away from this one just by the title, or draw people in with a chalange :) I'm writting this program in c++, however I'm using char* instead of the string class, I am ordered by my instructor and she does have her reasons so I have to use char*. So there is alot of c in the code as well Anyways, I have a linked...
0
1540
by: Michael Conlen | last post by:
I'm developing a net-snmp module that executes a 'show status' command on a MySQL server and advertises the values. My choices seem to be super concrete: one server, one set of results, the variables don't change, ever... moderatly concrete: multiple possible servers, one set of results each, the variables don't change, ever.. abstract:...
3
1913
by: Cheddar | last post by:
I'm back again with another problem. What I want is for the user to click a checkbox and have a list appear. I think the code is almost there but it doesnt seem to be working, grrrr. Can anyone help me out with it. Also is there a initial way to hide a list when the page is loaded? <html>
198
11402
by: Sy Borg | last post by:
Hello: We are designing two multi-user client server applications that performs large number of transactions on database servers. On an average Application A has a 50% mix of select and update/insert/delete statements and application B has 80-20 mix of select and update/insert/delete statements. Being able to scale the databases as needed...
8
2546
by: Galina | last post by:
Hello I have 6 dependent list boxes on my ASP page:  Faculty;  Lecturer;  Course;  Course occurrence;  Group;  Week commencing date. When faculty is selected, lists of lecturers and courses are populated. When course is selected, lists of occurrences, groups and
6
1596
by: rh0dium | last post by:
Hi all, I am having a bit of difficulty in figuring out an efficient way to split up my data and identify the unique pieces of it. list= Now I want to split each item up on the "_" and compare it with all others on the list, if there is a difference I want to create a list of the possible choices, and ask the user which choice of the...
2
1735
by: Ronald S. Cook | last post by:
I have many forms in my Windows project. When I go to create an inherited form, I see all my forms in the list of choices. HOWEVER, if any form is marked as must inherit, then it doesn't show up in the list! Is this a bug? Thanks, Ron
1
972
by: Ronald S. Cook | last post by:
I have many forms in my Windows project. When I go to create an inherited form, I see all my forms in the list of choices. HOWEVER, if any form is marked as must inherit, then it doesn't show up in the list! Is this a bug? Thanks, Ron
3
2788
by: fish919 | last post by:
Hello All, I am creating a date base in access. I want to create a dropdown list box that is connected to another dropdown list box. You start with a dropdown list that has 5 choices and each of these choices will call another dropdown list box when one of the choices from the first gets selected. (I hope this makes sense) All of this is...
0
7413
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...
0
7752
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...
1
7358
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...
0
7697
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...
1
5286
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...
0
3397
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...
1
1831
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
1
980
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
650
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...

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.