Compare two dropdowns in ASP.NET

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ganeshshegde
    New Member
    • Jun 2007
    • 8

    Compare two dropdowns in ASP.NET

    Hi,
    How can i compare values of two dropdown lists in .aspx page using javascript?

    I used following code-
    [code=javascript]

    function ValidateFlightR equest()
    {
    var vFromCombo = igcmbo_getCombo ById("ctl00_Sea rchBar1_ddlLeft searchFrom");

    var vToCombo = igcmbo_getCombo ById("ctl00_Sea rchBar1_ddlLeft searchTo");

    if(vFromCombo.g etSelectedIndex () == vToCombo.getSel ectedIndex())
    {
    alert("From Airport and two airport cann't be same");
    return false;
    }
    }[/code]
    Last edited by Frinavale; Jun 29 '07, 04:09 PM. Reason: Added [code] tags to make more legible
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by ganeshshegde
    Hi,
    How can i compare values of two dropdown lists in .aspx page using javascript?

    I used following code-
    [code=javascript]

    function ValidateFlightR equest()
    {
    var vFromCombo = igcmbo_getCombo ById("ctl00_Sea rchBar1_ddlLeft searchFrom");

    var vToCombo = igcmbo_getCombo ById("ctl00_Sea rchBar1_ddlLeft searchTo");

    if(vFromCombo.g etSelectedIndex () == vToCombo.getSel ectedIndex())
    {
    alert("From Airport and two airport cann't be same");
    return false;
    }
    }[/code]
    Hi Ganeshshegde!
    Welcome to theScripts, I hope you like it here!

    Why would you want to do this using JavaScript?
    Please note that people can easily by-pass JavaScript checks and submit invalid data to mess up your program.

    Anyways, I would do this check server side on button click.
    If it the arports match you could just set an error message in a label instead of using a JavaScript alert box.

    Is it absolutely necessary to use JavaScript for this?

    -Frinny

    Comment

    Working...