Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3273796
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:58:11+00:00 2026-05-17T18:58:11+00:00

i have a simple little form <form id=loginform> <input id=myinput type=text /> <input name=submit

  • 0

i have a simple little form

<form id="loginform"> <input id="myinput" type="text" /> <input name="submit" value="go" type="submit" /></form>

in a very not secure way i want it to go to different urls depending on the input value.

here is my simple little jquery script that i am sure could be written more succinctly. (feel free to help)

$(document).ready(function() {
jQuery.noConflict();
var apple = 'http://www.apple.com';
var microsoft = 'http://www.microsoft.com';

    jQuery('#loginform').submit(function() {
    var pass = jQuery('#myinput').val();

if (pass=='apple') {
var currentloc=apple;
} else if (pass=='microsoft') {
var currentloc=microsoft;
}
else {
var currentloc ='http://www.mysite.com/sorry'; 
}
        window.open(currentloc, 'formpopup', 'width=800,height=600,resizeable=1,scrollbars=1');
    });
});

this works when i run it on ffcurrent macintosh, but not when i run it in ie7. then the popup window is the same as the window we are coming from.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:58:11+00:00Added an answer on May 17, 2026 at 6:58 pm

    I think the main problem is that you declared currentloc as a local variable three times.

    In JavaScript it’s all about scope, and every time you declared currentloc with the key word var you were basically saying that “I want this variable to exist within this if (or else if) statement and not outside it.” Later on when you used window.open and you passed in currentloc, you were actually instantiating a new global variable since all other instances of currentloc had been lost.

    Global variables are automatically created when you don’t declare them with var (I think technically they are global properties of the global object, but I’m not 100% on that). In any case, it is considered a best practice to explicitly declare your variables and limit them to the minimum scope needed for your application.

    Here is your modified code. I hope it works (tested IE8 quirks mode, and Firefox)

    <html>
    <head>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" ></script>
        <script>
        $(document).ready(function() {
            jQuery.noConflict();
            var apple = 'http://www.apple.com';
            var microsoft = 'http://www.microsoft.com';
            var currentloc; 
    
            jQuery('#loginform').submit(function() 
            {
                var pass = jQuery('#myinput').val();
    
                if (pass=='apple') 
                {
                    currentloc=apple;
                } 
                else if (pass=='microsoft') 
                {
                    currentloc=microsoft;
                }
                else 
                {
                    currentloc ='http://www.mysite.com/sorry'; 
                }
                window.open(currentloc, 'formpopup', 'width=800,height=600,resizeable=1,scrollbars=1');
            });
        });
        </script>
    </head>
    <body>
        <form id="loginform"> 
            <input id="myinput" type="text" /> 
            <input name="submit" value="go" type="submit" />
        </form>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple HTML Form that allows the user to enter some text
I have a simple form containing a main view and also some text boxes
This is a very simple form that I have found on the web (as
I have a simple little test app written in Flex 3 (MXML and some
I have a simple webform that will allow unauthenticated users to input their information,
I have a simple setter method for a property and null is not appropriate
I have a simple form created using Ajax.BeginForm : <% using (Ajax.BeginForm(Update, Description, new
I have a simple form to enter details of a new case (kase), it's
I have a simple email address sign up form as follows: <form action= id=newsletterform
I have just got the following bloody MDA exception on a rather simple little

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.