string value in select tag not working as desired with strings

--0016e6db2e40bff15f04a3a772f0
Content-Type: text/plain; charset=ISO-8859-1

Hi

I have the following code:
When the option value is integer, the select button is working perfectly
selecting the option. In case when the value is string, the post value does
reflect the selected item in the selection box but does not select it. I am
totally confused what is wrong with my code.

<script language="JavaScript">
function autoSubmit()
{
var formObject = document.forms['theForm'];
formObject.submit();
}
</script>



<select name="organism" onChange="autoSubmit();">
<option value="null">Select Organism</option>
<option value= "9606" <?php if($organism == 9606) echo "
selected"; ?>>human</option>

<option value= "10090" <?php if($organism == 10090) echo " selected";
?>>mouse</option>
<option value= "10116" <?php if($organism == 10116) echo " selected";
?>>rat</option>
</select>


the above code does select the clicked entry in selection box but the
following code does not select the clicke item and always shows organism.

<select name="organism" onChange="autoSubmit();">
<option value="null">Select Organism</option>
<option value= 'human' <?php if(strcmp($organism, 'human') == 0) echo "
selected"; ?>>human</option>
<option value= 'mouse' <?php if(strcmp($organism, 'mouse') == 0) echo "
selected"; ?>>mouse</option>
<option value= 'rat' <?php if(strcmp($organism,'rat') == 0) echo "
selected"; ?>>rat</option>
</select>

Any help???
thanks

Fahim

--0016e6db2e40bff15f04a3a772f0--
Fahim M [ Do, 19 Mai 2011 23:11 ] [ ID #2059739 ]

Re: string value in select tag not working as desired with strings

On 19 May 2011 22:11, Fahim Mohammad <fahim.md [at] gmail.com> wrote:
> Hi
>
> I have the following code:
> When the option value is integer, the select button is working perfectly
> selecting the option. In case when the value is string, the post value do=
es
> reflect the selected item in the selection box but does not select it. I =
am
> totally confused what is wrong with my code.
>
> <script language=3D"JavaScript">
> function autoSubmit()
> {
> =C2=A0 =C2=A0var formObject =3D document.forms['theForm'];
> =C2=A0 =C2=A0formObject.submit();
> }
> </script>
>
>
>
> <select name=3D"organism" onChange=3D"autoSubmit();">
> =C2=A0 =C2=A0 =C2=A0<option value=3D"null">Select Organism</option>
> =C2=A0 =C2=A0 =C2=A0<option value=3D "9606" <?php if($organism =3D=3D 960=
6) echo "
> selected"; ?>>human</option>
>
> =C2=A0 =C2=A0 =C2=A0<option value=3D "10090" <?php if($organism =3D=3D 10=
090) echo " selected";
> ?>>mouse</option>
> =C2=A0 =C2=A0 =C2=A0<option value=3D "10116" <?php if($organism =3D=3D 10=
116) echo " selected";
> ?>>rat</option>
> </select>
>
>
> the above code does select the clicked entry in selection box but the
> following code does not select the clicke item and always shows organism.
>
> <select name=3D"organism" onChange=3D"autoSubmit();">
> =C2=A0 =C2=A0 =C2=A0<option value=3D"null">Select Organism</option>
> =C2=A0 =C2=A0 =C2=A0<option value=3D 'human' <?php if(strcmp($organism, '=
human') =3D=3D 0) echo "
> selected"; ?>>human</option>
> =C2=A0 =C2=A0 =C2=A0<option value=3D 'mouse' <?php if(strcmp($organism, '=
mouse') =3D=3D 0) echo "
> selected"; ?>>mouse</option>
> =C2=A0 =C2=A0 =C2=A0<option value=3D 'rat' <?php if(strcmp($organism,'rat=
') =3D=3D 0) echo "
> selected"; ?>>rat</option>
> </select>
>
> Any help???
> thanks
>
> Fahim
>

1 - There may be an issue with ...

key equals space quote - value=3D 'rat'

Instead, use

key equals doublequote - value=3D"rat"

2 - selected may need to be shown as selected=3D"selected"

I think this is a due to a difference in the HTML / XHTML standards,
so depending upon the doctype you are generating ...



--
Richard Quadling
Twitter : EE : Zend : PHPDoc
[at] RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/iZdpBR

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Richard Quadling [ Fr, 20 Mai 2011 12:20 ] [ ID #2059841 ]
PHP » gmane.comp.php.database » string value in select tag not working as desired with strings

Vorheriges Thema: multiple select: Selections not highlighted
Nächstes Thema: get form value javascript