Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi sir,
I have the drobdownlist which have two texts i.e Load File & Send Mail, I want when i select the appropriate word its go to their view through GO button, how i do this.
I am here the below code which not work.

This is my JS code.
XML
<head>
<script type="text/javascript">

    $("#go").click(function () {

        var tz = $("#Selector").val();
        var loader = "Email Loader";
        var Sender = "Send email";

        if (tz == loader) {
            document.location = '/Admin/Marketing/Load_File';
        }
        else if (tz == Sender)
        {
            document.location = '/Admin/Marketing/Send_Mail';
        }
    });

</script>
    </head>


This is my Drobdownlist & button code.
XML
             <select class="form-control input-sm" id="Selector">
                     <option value="1">Email Loader</option>
                     <option value="2">Send email</option>

                 </select>

             </div>
  <div class="row">
<button class="btn red"style=" float: left; margin-top: 10px; margin-left: 32px;" id="go">Go</button> </div>


Please help
Regards,
Tahir
Posted

1 solution

The problem with your code is that val returns the value attribute of the option, not its text.

JavaScript
var tz = $("#Selector").val(); // this gets the "value", not the selected item's text
var loader = "1";
var Sender = "2";

if (tz == loader) {
    document.location = '/Admin/Marketing/Load_File';
}
else if (tz == Sender) {
    document.location = '/Admin/Marketing/Send_Mail';
}


Simple debugging of your code would have shown you this, if you learn how to debug your code then problems like this are easily solvable yourself. Another way of doing it would be like this;

XML
<select class="form-control input-sm" id="Selector">
    <option value="/Admin/Marketing/Load_File">Email Loader</option>
    <option value="/Admin/Marketing/Send_Mail">Send email</option>
</select>


C#
var tz = $("#Selector").val();
document.location = tz;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900