DOCTYPE not working in Firefox

Go To StackoverFlow.com

0

     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"         
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
     <html>
    <head>
    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="Pragma"  content="no-cache">
    <meta http-equiv="Expires" content="-1">

        <Script language = JavaScript>
            function addOptionList(selectbox,text,value )
            {
                var optn = document.createElement('OPTION');
                optn.text = text;
                optn.value = value;
                selectbox.options.add(optn);
            }
            function removeOptionList(listbox,i){
                listbox.remove(i);
            }
            function addOption_list(fromvar,tovar){ 
                for(i=fromvar.options.length-1;i>=0;i--)    {
                    var userlist=fromvar;
                    if(fromvar[i].selected){
                        addOptionList(tovar, fromvar[i].value, fromvar[i].value);
                        removeOptionList(userlist,i);

                    }
                }
            }

        </Script>

    <table align='center'>
        <tr>
            <td ><select multiple name='userlist' id='userlist' >
                <option value='aaa'>aaa</option>
                <option value='bbb'>bbb</option>                
            </select></td>
            <td align='center' valign='middle'>
                <input value='--&gt;'  
                     onClick='addOption_list(userlist,pouser);' type='button'>
                <br><input value='&lt;--' 
                     onClick='addOption_list(pouser,userlist);' type='button'></td>
            <td><select multiple  name='pouser' id='pouser'>
                <option id='test' value='ccc'>ccc</option>              
            </select></td>
        </tr>
    </table>
</body>
</HTML>

I am using the code above to select a name from left box and move it to the right box. The code is working in IE with/without DOCTYPE. But when I use DOCTYPE, it stops working in Firfox. I have spent a lot of time on it, but still couldn't figure out the problem. Also, I am a novice in Javascript, so please explain me the problem with code below (when I am using DOCTYPE). Thanks in advance for your help!!

2012-04-05 18:45
by user968014


1

You're relying on elements with ids showing up as global properties on the window (e.g. userlist). Firefox only does that in quirks mode, which is why the doctype matters.

2012-04-06 01:42
by Boris Zbarsky
Thanks BOris. So how do I define it locally? Please let me know.Thanks! - user968014 2012-04-06 17:11
Use document.getElementById("userlist")Boris Zbarsky 2012-04-06 19:11


0

Your markup does not match the DOCTYPE. I.e. you are not using valid XHTML 1.0 markup.

Paste you code into the xhtml validator and it will show you what's wrong.

2012-04-05 19:50
by Griffin
Thanks Griffina. Below pasted is the validated code from XHTML validator. It's still not working.:-( It's not letting me paste my updated code - user968014 2012-04-05 21:20
Ads