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

1
  • Case sensitive "Short Meeting" and "Short meeting Commented Nov 22, 2012 at 10:51

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

That was the Problem -.-. Thanks for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.