0

Moz say's everything is ok! IE say's object expected everywhere..

for example this my make a box function (in all.js file);

function kutuyap(Eid,iduzan,text,yer,ekle){

var div;
 if (document.createElement && (div = document.createElement('div'))) {
  div.name = div.id = Eid+iduzan;
  document.getElementById(yer).appendChild(div);

  }
 //$('#'+yer).append("<div id="+Eid+iduzan+"></div>")


 $('#'+Eid+iduzan).addClass("minikutu");
 $('#'+Eid+iduzan).html("&nbsp;"+text+'<span id='+Eid+'y'+iduzan+' class="yokedici">X</span>');
    $("#"+Eid+'y'+iduzan).attr("onclick","kutusil('"+Eid+"y"+iduzan+"','"+iduzan+"','"+ekle+"');");
 $('#'+ekle).val($('#'+ekle).val()+Eid+'-');

}

and after that i call function like this;

HTML;

  <select name="Mturs" class="inputs" id="Mturs">

    <option value="0" selected="selected">Choise One</option>
    <option value="4">Pop</option>
    <option value="3">Pop-Rock </option>
    <option value="5">Rock (Yabancı)</option>

  </select>

<input name="secMtur" id="secMtur" value="" type="hidden">

 <script>
 $('#Mturs').live('change', function() {

 $('#Mturs :selected').each(function (i) {

          if ( $('#Mturs :selected').val() != 0 ) {

 secMturde=$('#secMtur').val().indexOf($('#Mturs :selected').val()+'-');

splitter=$('#secMtur').val().split("-")
if(splitter.length<=12){

if (secMturde<0) {
 kutuyap($('#Mturs :selected').val(),'mtur',$(this).html(),'divmtur','secMtur');
 }else{
   alert("Choisen before")
 }

 }else{
     alert("Max limit is 12 !")
   }

}
});
});
 </script>

sory for my realy bad english..

edit: and i have this tags;

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js">
</script>
<script type="text/javascript" src="alljs.js"></script>
3

3 Answers 3

1
$("#"+Eid+'y'+iduzan).attr("onclick","kutusil('"+Eid+"y"+iduzan+"','"+iduzan+"','"+ekle+"');");

Don't use attr to set event handlers like onclick, it won't generally work in IE.

It's also a really bad idea to be creating JavaScript code from strings in that way, too. Especially as if any of those variables can include a ', ", \, &, < or U+2018/2019 character you've got trouble.

Instead use inline function expressions, picking up the variables you already have from the outer function using a closure:

$("#"+Eid+'y'+iduzan).click(function() {
    kutusil(Eid+'y'+iduzan, iduzan, ekle);
});

Again:

$('#'+Eid+iduzan).html("&nbsp;"+text+...

If text can contain </& you've potentially got cross-site-scripting problems there. Don't stick HTML strings together from text content. Use .text(text) to write plain text to an element.

if (document.createElement && (div = document.createElement('div'))) {

There is no need for this checking. document.createElement exists in every browser (it is DOM Level 1 Core) and can never return null.

div.name

There's no such property on divs.

Sign up to request clarification or add additional context in comments.

2 Comments

ok i made a test page with my code and IE says nothing(no more object expected error) also do nothing and change my code like this.. but nothing change.. yetkineren.com/testpage.html
You appear to be using jQuery 1.3. live change events don't work in IE under this version of jQuery. Either change to 1.4, or replace .live('change', ... with a normal .change(... binding. (You don't appear to be doing anything that requires live binding.)
1

bobince's answer is excellent; do pay very careful attention to XSS vulnerabilities.

I would add only one other tidbit that caused me some consternation early on, and is a best practice that you should consider adopting:

Do not use primitives or core attribute/function names in your script unless you are purposefully doing so (e.g in the case of overriding).

Take this example:

01:     $.getJSON('/doSomething.php?r=' + new Date().getTime(),function(json){
02:         var someinfo = "";
03:         $.each(json.somearray, function(i,data){
04:             someinfo = someinfo + data.class + " ";
05:         });
            ...

Mozilla is perfectly fine with the above code; Internet Explorer, however, chokes on the ".class" reference (line 04).

This issue can be difficult to identify since the error prevents IE from parsing other javascript on the page; the result is that IE throws an error on all (custom) function calls, rather than just the function where the actual problem is.

The solution, as previously mentioned, is to replace ".class" with some other string

 04:                someinfo = someinfo + data.classification + " ";

Happy coding!

Comments

0

Try changing this:

src="ajax.goog...

to this:

src="http://ajax.goog...

Usually the http:// is necessary, this might be why your scripts were not loaded.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.