473,587 Members | 2,320 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 1511
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
2366
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
4814
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
1547
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
1921
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
11459
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
2557
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
1598
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
1737
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
974
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
2796
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
8206
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8340
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
7967
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
6621
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
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...
0
3875
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2353
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
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.