-1

I have a dropdown list box. If a user hasn't selected anything, it should not go to next page. For that I tried something. That code works fine in IE and Chrome. But it's going next page in Firefox. Why this?

<td width="100" align="right">
    <div style="text-align:center;">
       <input type="button" value="Next" align="top" style="width: 70px;" ONCLICK="gt();">
    </div>
</td> 

<script type="text/javascript">
    function gt_nextPage()
    {
        var e=document.getElementById("ParentType");
        var val=e.options[e.selectedIndex].value;
        window.location.replace("gt_Iba1?value="+val);
    }

    function gt()
    {
        var e=document.getElementById("ParentType");
        var val=e.options[e.selectedIndex].value;
        if(val != null)
        {
            gt_nextPage();  
        }
        if(val === "")
        {
            alert("Please select any value");
            window.location.replace("gt_Iba?value="+val);
        }
    } 
</script> 

I have added this inside my jsp page.

4

1 回答 1

2

尝试这个

function gt()
{
    var e=document.getElementById("ParentType");
    var val=e.options[e.selectedIndex].value;
    if(val != null && val !== "")
    {
        gt_nextPage();  
    }
    else
    {
        alert("Please select any value");
        window.location.replace("gt_Iba?value="+val);
    }
} 
于 2013-08-08T06:40:16.940 回答