> > I need help to make the following code works in IE :
> >
> > document.writeln("<select name=\""+name+"\"
> id=\""+name+"\""+((multiple!=null)?" "+multiple:"")+">");
> > var tablename = "some_table";
> > $("#"+name).load("table_query.php", {table: tablename});
> > document.writeln("<\/select>");
> >
> > Script table_query.php return <option> elements. This code work well
> > in Firefox, but in IE, the select had no option.
> > I tried to change table_query.php result to xml, and use
> > following code...
>
> In both the original code and the lengthier version, you are trying to
> access the DOM while you're in the middle of writing the document. There's
> no guarantee that this would work in any browser.
>
> When it fails, did you look at the result of $("#"+name) in the debugger to
> see if it actually contains any elements?
The $("#"+name) refer to the right element. It behave correctly in Firefox. Maybe in IE, there a difference in what functions to do fist, document.write or $().load, so it will break.
I have another script, where I use ajax to fetch another select's options when the first select change :
.....
<?php } else if ($type=='select') { ?>
<?php $multiple = $formXML->GetProperties($line, 'multiple'); ?>
<select name="<?php echo $name; ?>" id="<?php echo $name; ?>"<?php echo (($multiple!='')?' multiple':''); ?>>
<?php foreach ($formXML->GetOptions($line) as $optionlabel => $optionvalue) { ?>
<option value="<?php echo $optionvalue; ?>"<?php echo (($optionvalue==$input_value) ? ' selected="selected"':''); ?>><?php echo $optionlabel; ?></option>
<?php } ?>
<?php if ($formXML->GetTable($line, 'name') != "") { ?>
<?php $tablename = $formXML->GetTable($line, 'name'); ?>
<?php include('table_query.php'); ?>
<?php } ?>
</select><?php if (isset($notes) && ($notes!='')) { ?><?php if (isset($notes_pos) && ($notes_pos=='left')) { ?> <?php } else { ?><br /><?php } ?><span class="notes"><?php echo $notes; ?></span><?php } ?>
<?php if ($formXML->GetTable($line, 'parameter') != "") { ?>
<script type="text/_javascript_">//<![CDATA[
$("#<?php echo $formXML->GetTable($line, 'parameter'); ?>").change(function () {
var newparam = this.value;
$("#<?php echo $formXML->GetTable($line, 'name'); ?>").load("table_query.php", {table: "<?php echo $formXML->GetTable($line, 'name'); ?>", parameter: newparam});
} );
//]]></script>
<?php } ?>
<?php } else if ($type=='file') { ?>
.....
In Firefox, the script work well. When the first select change, the other select element replaced with a new element from ajax call. In IE6, it result an empty select.
I tried to use $().get, and IE produce select with eah options have null label. When I submit the form, the select element send a correct value.
Both way, $().load and $().get works well in Firefox. Looks like I had to add "No IE6 viewer" in my page ;)
> At the very least, you should defer the attempt to reference the DOM:
>
> $( function() {
> $("#"+name).load("table_query.php", {table: tablename});
> });
>
> Also, a few tips on the string handling:
>
> * You don't need to escape forward slashes.
>
> * Use single quotes for your strings so you don't need to escape the double
> quotes inside the strings.
>
> * Use Array.join instead of string concatenation. On many browsers, it is
> much faster. In a case like this it won't make any noticeable difference,
> but if you are doing a lot of string concats it really helps. So it's good
> to get in the habit of using Array.join.
>
> Putting that all together, you may end up with something like this:
>
> document.writeln( [
> '<select name="', name, '" id="', name, '"',
> multiple != null ? ' ' + multiple : '',
> '>',
> '</select>'
> ].join('') );
>
> $( function() {
> $("#"+name).load("table_query.php", {table: tablename});
> });
>
> -Mike
Thanks for the suggestions :)
--
Donny Kurnia
http://hantulab.multiply.com/
http://hantulab.blogspot.com/
-------------------------------------------
At times the world can seem an unfriendly and sinister place. But believe us when we say there is much more good in it than bad. And what might seem to be a series of unfortunate events, may in fact, be the first steps of a journey.
-- A Series of Unfortunate Events
_______________________________________________ jQuery mailing list [email protected] http://jquery.com/discuss/
