Click to See Complete Forum and Search --> : Select question


tbirnseth
09-24-2005, 01:06 AM
Hi all,

A couple of questions. When a <select> is SELECTED, shouldn't the form send the selected value even if the selection wasn't changed? I.e. this code segment
does not always return the SELECTED option. I've been pulling my hair out tryiing to figure it out.

2nd point - anyone else run into the FireFox bug where if "SELECTED" is not immediately adjacent to the ending quote of the value it is not always picked up? I've seen this one too.

<select name="pType[Debug]" id="pType[Debug]" >
<option value="1"> string </option>
<option value="2"SELECTED > bool </option>
<option value="3"> int </option>
<option value="4"> path </option>

<option value="5"> prompt </option>
</select>

Segment of the form processing is:

foreach($updateList as $param) {
$pName[$param] = isset($_POST['pName'][$param]) ? $_POST['pName'][$param] : '';
$pType[$param] = isset($_POST['pType'][$param]) ? intval($_POST['pType'][$param]) : 0;
if( $pType[$param] == 0 )
TBdebug(sprintf("POST[pTYPE][%s} is NOT set!!!", $param));

The debug statement is executed for some (but not all) of the 'pType' POSTS.

I'm stumped and figure that I've probably been doing something wrong for a long time and have stumbled across it now that I'm using arrays for holding the records.

Any help is greatly appreciated.

tony

chrisrock79
09-24-2005, 02:59 AM
Tony, I wish I could help. I can recommend that you ask this question in a server side forum because nothing is wrong with your HTML.

Chris

Fang
09-24-2005, 06:43 AM
Two things wrong with the HTML: id and name are invalid (http://www.w3.org/TR/html401/types.html#type-id) and there should be a space before SELECTED

NogDog
09-24-2005, 06:54 AM
Two things wrong with the HTML: id and name are invalid (http://www.w3.org/TR/html401/types.html#type-id) and there should be a space before SELECTED
Hmmmm....interesting in that PHP supports a technique whereby if the name assigned to a form element ends in "[]" (such as name="test[]") then it saves it as and element of array "name" in the $_POST array (i.e.: $_POST['name'][0]). So in order to use that feature you have to write what technically are invalid name tokens, though I've never had a problem with it working when I've done so.

Charles
09-24-2005, 07:17 AM
Actually, that's a valid "name" but an invalid "id". I got called on this one a few months ago and am grateful to that soul who set me right.

We are concerned here with three data types, CDATA, ID and NAME tokens.*CDATA is a sequence of characters from the document character set and may include character entities. User agents should interpret attribute values as follows:
- Replace character entities with characters,
- Ignore line feeds,
- Replace each carriage return or tab with a single space.

...

* ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
http://www.w3.org/TR/html401/types.html#h-6.2 As you would expect, "id" attributes take ID tokens. But I never would have guessed that "name" attributes don't, as a rule, take NAME tokens. Those are exclusively for the "name" and "http-equiv" attributes in META elements. The rest are just CDATA.

However, if you use both "name" and "id" with an element they must be set to the same value. So we need to drop the brackets or drop the "id" attribute.

Fang
09-24-2005, 09:07 AM
That's one to remember!

tbirnseth
09-25-2005, 04:27 AM
I will try removing the id's (not sure what good they actually are anyway since I'm not using any CSS references to them.

Regarding one poster's note about having a space between the last quote of the value and SELECTED, when I do that, Firefox seems to ignore the SELECTED argument.

This is turning out to be a mess. It's the first time I've tried to use arrays in forms. Seemed really handy. I'll probably just go back to a naming construct whereby I prepend and identifier to the name that is unique to each row of data. But I want to be sure it's not my but (in the code that's generating all of this) before I start ripping it apart. Because if it is my bug, then it will probably sting me again or somewhere else. Pesky little critters.

I'll play with it tomorrow or Monday (kind of took today off and went fishing) and let you all know what I find.

Thanks for all the responses. Like most, there's quite a variety.

cheers,
tony

tbirnseth
09-26-2005, 11:37 PM
Just an update. NogDog found my problem. I had named two different fields the same. Hence the browser was using the last referenced name to return the values.

So I was referencing a type instead of a value.

Thanks again NogDog, you're tops!

tony