1

Hi i have the following javascript and DropDownList:

function loadanlasstyp(ddl) {
            var ControlName = document.getElementById(ddl.id);

            if (ControlName.value == "Event") {
                window.location = "../book/event.aspx";

            }

            else if (ControlName.value == "Short Meeting") {
                window.location = "../book/shortmeeting.aspx";
            }
            return true;

        }

DropDownList:

<asp:DropDownList ID="ddlAnlasstyp" runat="server" CssClass="ff" Height="21px" onChange="javascript:loadanlasstyp(this)"
                        TabIndex="3" Width="150px">
                        <asp:ListItem Value="Short meeting">Short</asp:ListItem>
                        <asp:ListItem Value="Event">Event</asp:ListItem>
</asp:DropDownList>

I have the Javascript function and the Dropdownlist on both Pages, so that i can switch between them. "Shortmeeting.aspx" is loading per default. I can switch from "Shortmeeting.aspx" to "Event.aspx" if i click "EVENT" in the DropDownList. Now if i want to Switch back to "Shortmeeting.aspx", for that i click on "SHORT" in the DropDownList, but it does not work.

How can i switch between these two pages correcly? Please Help

Paks
  • 1,460
  • 6
  • 26
  • 46

1 Answers1

1

Just remove the empty space in value

Value="Short meeting"

     to 

Value="Short"

else if (ControlName.value == "Short") {
            window.location = "../book/shortmeeting.aspx";
        }

Empty spaces creates problems sometimes when doing string match comparison. you can create a string comparison function for future reference.

function strcmp(a, b) {
if (a.toString() < b.toString()) return -1;
if (a.toString() > b.toString()) return 1;
return 0;

}

function strcmp(a, b) {
    a = a.toString(), b = b.toString();
    for (var i=0,n=Math.max(a.length, b.length); i<n && a.charAt(i) === b.charAt(i); ++i);
    if (i === n) return 0;
    return a.charAt(i) > b.charAt(i) ? -1 : 1;
}

see this link for reference link

Community
  • 1
  • 1
Shazhad Ilyas
  • 1,183
  • 8
  • 14