0

I would like to add new attribute to select box which name and id are 'firm_id'. So far I have tried with this code, its working fine in mozila but not working in IE.

I am doing this with javascript because select box is coming from ajax. The function sbmtfrm() is not calling in IE.

Error: Message: 'FB' is undefined.

May be FB is a object called in my js lib files, but now i am writing code within a another saperate script tag.

<script type="text/javascript">

    function sbmtfrm()
    {
       alert('now submitting...');
       document.frmsearch.submit();
    }

    function setOnclickAtt(name)
    {
        alert("'"+name+"'" + document.getElementById(name).getAttribute('onchange'));
        alert(document.getElementById(name));
        if(document.getElementById(name))
        {
            alert('attrr changed');
            var ref = document.getElementById(name);
            ref.setAttribute('onchange', 'sbmtfrm();');
            alert("now new atrr = " + document.getElementById(name).getAttribute('onchange'));
        }
        else
        {
            alert('again');
            setTimeout("setOnclickAtt('firm_id')",100);
        }
    }

    setOnclickAtt('firm_id');

</script>   

Any suggestion or ideas would be greatly appreciated.

Thanks a lot.

4
  • IE doesn't like whatever FB is, it errors and so will not execute subsequent javascript. You need to fix the FB problem wherever it is. Commented Dec 14, 2011 at 12:37
  • Doesn't matter if you're using another script tag. Seach for FB in your project files and check its use by JS scripts. Commented Dec 14, 2011 at 12:39
  • but why this code block is not running, other functions are calling correctly ? Commented Dec 14, 2011 at 12:40
  • why function setOnclickAtt(name) calling and working, And sbmtfrm() not calling nor working Commented Dec 14, 2011 at 12:43

1 Answer 1

1

I think IE is picky when it comes to event handling. Try:

ref.onchange = sbmtfrm;

instead of:

ref.setAttribute('onchange', 'sbmtfrm();');

Also, I think the error message has nothing to do with this issue. It´s wrong but it´s another issue.

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

3 Comments

Maybe you could put up some minimum viable code on jsfiddle.net so we could fix it.
Acctually now code is working fine but a doubt is that you can see that i have alerted after setting the new attribute "now new atrr = sbmtfrm()", but its getting old attribute, why so i dont know but working fine. :) Nice
My guess is that event handling is in many cases magic and do not behave like normal attributes.

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.