473,382 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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

40
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("SELECT * FROM mytbl WHERE incident_id = '$_GET[id]'",$db);

$ID = $_GET['id'];
while ($myrow = mysql_fetch_array($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 1502
acoder
16,027 Expert Mod 8TB
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
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...
7
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...
0
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...
3
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...
198
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...
8
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...
6
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...
2
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...
1
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...
3
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.