I've constructed a "combo box"-like select control using data from
MySQL, like this:
echo "<SELECT name='selectStation' SIZE='1' style='width:150px;'>";
foreach ($myArray as $arrayItem) {
echo "<option value='$arrayItem'".
(($arrayItem == $equipmentRecord['Location']) ?
"selected='selected'" : "null").
" onClick='javascript:SubmitSerial();'>$arrayItem</option>";}
echo "</SELECT>";
This works perfectly in Firefox, but in IE and Chrome it doesn't respond
to my user. The box draws fine and my user can select another value from
the box, but the value specified by $equipmentRecord['Location'] is not
selected and the 'onclick' event won't fire my javascript function.
Any help is appreciated. Happy to supply more info if anyone wants it.
Some browsers don't handle single quotes too well, I do suggest you use double
quotes to enclose data in the html-tags.
Don't use null in the html tag, just use an empty string instead.
Don't write together options, for example
<option value='something'selected='selected'
onClick='javascript:SubmitSerial();'>something</option>
don't work that well in all browsers.
If you use style, then take a step further and use css files and classes, then
you don't have to hack in your code to change the look.
function use_functions_which_returns_values($myArray) {
if(is_array($myArray) && count($myArray)) {
$string = '<select name="selectStation" size="1" class="selectStation">'."\n";
foreach($myArray as $arrayItem) {
$selected = ($arrayItem == $equipmentRecord['Location'])?'
selected="selected" ':'';
$string .= <<<EOS
<option value="{$arrayItem}" onclick="javascript:SubmitSerial();"
{$selected}>{$arrayItem}</option>
EOS;
}
$string .= '</select>'."\n";
} else
$string = 'No drop down';
return $string;
}
When it comes to your javascript bug, I suggest you use tools like firebug,
Chromium has it's own built in, MSIE you need to use visualstudio.
--
//Aho
Try a javascript newsgroup.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================
>Arch wrote:
>> [...]
>>
>> This works perfectly in Firefox, but in IE and Chrome it doesn't respond
>> to my user. The box draws fine and my user can select another value from
>> the box, but the value specified by $equipmentRecord['Location'] is not
>> selected and the 'onclick' event won't fire my javascript function.
>
>Some browsers don't handle single quotes too well
Which?
>I do suggest you use double
>quotes to enclose data in the html-tags.
Both is allowed and works perfectly well.
Micha
Grateful noob. :|
Changed the 'onClick' event to 'onChange' and moved it to the SELECT
line instead of the individual Option lines. Works perfectly on all
browsers.
Great. And next time, please ask your javascript questions in a
javascript newsgroup.
In case you haven't figured out - this newsgrout is alt.PHP, not
alt.JAVASCRIPT.
Correct. That's a big reason why I recommend people ask javascript
questions (even simple ones) in a javascript newsgroup. Too many bad
answers in this newsgroup.
Jer, here's your vocabulary builder word of the day: "Pissant"
Please note that I had the class to ignore you the first time.
He can be very complicated some times and there are many things where I
don't agree with him, but here he was right - your problem had _nothing_
to do with PHP.
Think about it - PHP runs on the server. The browser just receives the
HTML, without knowing how it was created. So if there's a problem in
some browser, but not in another, obviously it _can't_ be a PHP problem,
because both browsers get exactly the same markup.
Micha
And here's your "words of the day"
CLUELESS IDIOT
Note that I was trying to be polite to you the second time. But it's no
use trying to be polite to a jack ass.