Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Feb 2010
    Posts
    38
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Browser compatibility and JavaScript

    Dear all, can somebody help me with browser compatibility and this code. Working fine in Opera and Firefox, but do not working in Internet Explorer and Chrome. With one form working fine in every browser, but when I put second form it stops to work in Explorer and Chrome.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    	"http://www.w3.org/TR/html4/strict.dtd">
    <HTML>
    <HEAD>
    <META http-equiv=Content-Type content="text/html; charset=UTF-8">
    <SCRIPT type="text/javascript">
    function showDiv(divIndex) {  var f=document.forms[0];  var d=f.getElementsByTagName('div');
    for(i=0;i<d.length;i++)d[i].style.display='none'
    d[divIndex].style.display = 'block';
    }
    </SCRIPT>
    </HEAD>
    <BODY>
    <form>
    <select onchange="showDiv(this.value); ">
    <option value="0" selected>option 1</option>
    <option value="1">option 2</option>
    <option value="2">option 3</option>
    </select>
    
    
    <div style="display:block;"><form action="001.htm" method="get" >
    Your state<br> 
    <select name="statecode" id="statecode">
    <option value="">Choose State for option 1...</option>
    <option value="AK">Alaska</option>
    <option value="AL">Alabama</option>
    <option value="AR">Arkansas</option>
    </select> 
    <input type="submit" name="search" value="Get Quotes" />
    </form></div>
    
    <div style="display:none;"><form action="002.htm" method="get" >
    Your state<br> 
    <select name="statecode" id="statecode">
    <option value="">Choose State for option 2...</option>
    <option value="AK">California</option>
    <option value="AL">Colorado</option>
    <option value="AR">Connecticut</option>
    </select> 
    <input type="submit" name="search" value="Get Quotes" />
    </form></div>
    
    <div style="display:none;"><form action="003.htm" method="get" >
    Your state<br> 
    <select name="statecode" id="statecode">
    <option value="">Choose State for option 3...</option>
    <option value="AK">Massachusetts</option>
    <option value="AL">Maryland</option>
    <option value="AR">Maine</option>
    </select> 
    <input type="submit" name="search" value="Get Quotes" />
    </form></div>
    
    </form>
    </BODY></HTML>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,247
    Thanks
    203
    Thanked 2,555 Times in 2,533 Posts
    You must give both forms a (different) name.


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,151
    Thanks
    80
    Thanked 4,559 Times in 4,523 Posts
    YOu can *NOT* have NESTED <form>s. Period. Not allowed. At all.

    If it happens to work in some browsers, you are (a) lucky and (b) the browsers are wrong.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,151
    Thanks
    80
    Thanked 4,559 Times in 4,523 Posts
    Quote Originally Posted by Philip M View Post
    You must give both forms a (different) name.
    ??? why?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,151
    Thanks
    80
    Thanked 4,559 Times in 4,523 Posts
    No names on any of the <form>s. Works in all browsers.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    	"http://www.w3.org/TR/html4/strict.dtd">
    <HTML>
    <HEAD>
    <META http-equiv=Content-Type content="text/html; charset=UTF-8">
    <SCRIPT type="text/javascript">
    function showDiv(divIndex) 
    {  
        var holder = document.getElementById("subforms");
        var subdivs = holder.getElementsByTagName("div");
        for( var i=0; i < subdivs.length; i++ )
        {
            subdivs[i].style.display = ( i == divIndex ) ? "block" : "none";
        }
    }
    </SCRIPT>
    </HEAD>
    <BODY>
    <form>
        <select onchange="showDiv(this.value); ">
        <option value="0" selected>option 1</option>
        <option value="1">option 2</option>
        <option value="2">option 3</option>
        </select>
    </form>
    
    <div id="subforms">
        <div style="display:block;">
            <form action="001.htm" method="get" >
            ONE: Your state<br> 
            <select name="statecode" id="statecode">
            <option value="">Choose State for option 1...</option>
            <option value="AK">Alaska</option>
            <option value="AL">Alabama</option>
            <option value="AR">Arkansas</option>
            </select> 
            <input type="submit" name="search" value="Get Quotes" />
            </form>
        </div>
    
        <div style="display:none;">
            <form action="002.htm" method="get" >
            TWO: Your state<br> 
            <select name="statecode" id="statecode">
            <option value="">Choose State for option 2...</option>
            <option value="AK">California</option>
            <option value="AL">Colorado</option>
            <option value="AR">Connecticut</option>
            </select> 
            <input type="submit" name="search" value="Get Quotes" />
            </form>
        </div>
    
        <div style="display:none;">
            <form action="003.htm" method="get" >
            THREE: Your state<br> 
            <select name="statecode" id="statecode">
            <option value="">Choose State for option 3...</option>
            <option value="AK">Massachusetts</option>
            <option value="AL">Maryland</option>
            <option value="AR">Maine</option>
            </select> 
            <input type="submit" name="search" value="Get Quotes" />
            </form>
        </div>
    </div>
    </BODY>
    </HTML>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    young_coder (11-15-2010)

  • #6
    New Coder
    Join Date
    Feb 2010
    Posts
    38
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Thank you very much Old Pedant! This working perfectly


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •