> 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?

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


_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to