-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.

Vignesh Vino
  • 1,242
  • 4
  • 25
  • 50

1 Answers1

2

Try this

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);
    }
} 
omma2289
  • 54,161
  • 8
  • 64
  • 68
  • Is that `!==` correct? A double equal sign?? Shouldn't it be `!=` – Eric Aug 08 '13 at 07:45
  • 1
    @munyul Check [this related question](http://stackoverflow.com/questions/359494/does-it-matter-which-equals-operator-vs-i-use-in-javascript-comparisons) – omma2289 Aug 08 '13 at 22:59