469,644 Members | 1,980 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,644 developers. It's quick & easy.

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 1392
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

Post your reply

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

Similar topics

2 posts views Thread by Jefferis NoSpamme | last post: by
7 posts views Thread by Chris Ritchey | last post: by
reply views Thread by Michael Conlen | last post: by
198 posts views Thread by Sy Borg | last post: by
6 posts views Thread by rh0dium | last post: by
2 posts views Thread by Ronald S. Cook | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.