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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 19 May 2011 22:11, Fahim Mohammad <fahim.md@xxxxxxxxx> 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 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
>

1 - There may be an issue with ...

key equals space quote - value= 'rat'

Instead, use

key equals doublequote - value="rat"

2 - selected may need to be shown as selected="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
@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




[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux