1

I'm working on this form select condition that will load a specific page when the submit button is clicked. Right now i'm getting a Unexpected Token error for windows.location. All files are in the same folder

<script>
$(document).ready(function() {
    $("#process_app").submit(function() {
        var selrange = $("select#range").val();
        var selplace = $("select#place").val();
        var selindustry = $("select#industry").val();

        if (selrange = '1') {
            // if value 1 load US short app, if value 2 load Canada short app
            window.location = selplace = "1" ? 'application_us_short.php' : 'application_ca_short.php');
        }
        if ((selrange = '2') && (selindustry = '2' || selindustry = '10')) {
            window.location = selplace = "1" ? 'application_us_short.php' : 'application_ca_short.php');
        } 
        if ((selrange = '2') && (selindustry != '2' || selindustry != '10') || selrange = '3')  {
            window.location = selplace = "1" ? 'application_us.php' : 'application_ca.php');
        }         

    });
});
    </script>

        <div style="margin: 0 auto; text-align: center; margin-top: 60px">
            <form id="app_type">
            <h4>What country are you located in?</h4>
            <select id="place" name="place" onchange="location = this.options[this.selectedIndex].value;">
                <option value="1">United States</option>
                <option value="2">Canada</option>
            </select>
            &nbsp;
            <h4>What industry is your company most closely associated with?</h4>
            <select id="industry" name="industry" onchange="location = this.options[this.selectedIndex].value;">
                <option value="1">Agriculture</option>
                <option value="2">Consumer Electronics &amp; Appliances</option>
                <option value="3">Construction/Industrial</option>
                <option value="4">Manufactured Housing</option>
                <option value="5">Marine</option>
                <option value="6">Music</option>
                <option value="7">Outdoor Power Equipment</option>
                <option value="8">Power Sports</option>
                <option value="9">Recreational Vehicles</option>
                <option value="10">Technology</option>
                <option value="11">Trailer</option>
            </select>
            &nbsp;
            <h4>What credit line range are you applying for?</h4>
            <select id="range" name="range" onchange="location = this.options[this.selectedIndex].value;">
                <option value="1">Less than $150,000</option>
                <option value="2">$150,001-$350,000</option>
                <option value="3">$350,000+</option>
            </select>
            <hr>
                <input type="submit" value="Submit" id="process_app" />
            </form>
        </div>
acctman
  • 4,229
  • 30
  • 98
  • 142

4 Answers4

0

You are assinging values instead of comparing

selplace = "1"

Try like this

selplace == "1"
Anik Islam Abhi
  • 25,137
  • 8
  • 58
  • 80
0

You are assigning values instead of checking it

Your Code

 window.location = selplace = "1" ? 'application_us_short.php' : 'application_ca_short.php'); 

Suggested change

 window.location = selplace === "1" ? 'application_us_short.php' : 'application_ca_short.php');

For more details visit Which equals operator (== vs ===) should be used in JavaScript comparisons?

Community
  • 1
  • 1
Dnyanesh
  • 2,265
  • 3
  • 20
  • 17
0

Try this and i change bracket in your if statement

$(document).ready(function() {
    $("#app_type").submit(function() {
        var selrange = $("select#range").val();
        var selplace = $("select#place").val();
        var selindustry = $("select#industry").val();
    

        if (selrange == '1') {
            // if value 1 load US short app, if value 2 load Canada short app
            window.location = selplace = "1" ? 'application_us_short.php' : 'application_ca_short.php';
        }
        if ((selrange == '2') && (selindustry == '2' || selindustry == '10')) {
            window.location = selplace = "1" ? 'application_us_short.php' : 'application_ca_short.php';
        } 
        if ((selrange == '2') && (selindustry != '2' || selindustry != '10') || (selrange = '3'))  {
            window.location = selplace = "1" ? 'application_us.php' : 'application_ca.php';
        }       
      alert(window.location);
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"> </script>     
<div style="margin: 0 auto; text-align: center; margin-top: 60px">
            <form id="app_type">
            <h4>What country are you located in?</h4>
            <select id="place" name="place" onchange="location = this.options[this.selectedIndex].value;">
                <option value="1">United States</option>
                <option value="2">Canada</option>
            </select>
            &nbsp;
            <h4>What industry is your company most closely associated with?</h4>
            <select id="industry" name="industry" onchange="location = this.options[this.selectedIndex].value;">
                <option value="1">Agriculture</option>
                <option value="2">Consumer Electronics &amp; Appliances</option>
                <option value="3">Construction/Industrial</option>
                <option value="4">Manufactured Housing</option>
                <option value="5">Marine</option>
                <option value="6">Music</option>
                <option value="7">Outdoor Power Equipment</option>
                <option value="8">Power Sports</option>
                <option value="9">Recreational Vehicles</option>
                <option value="10">Technology</option>
                <option value="11">Trailer</option>
            </select>
            &nbsp;
            <h4>What credit line range are you applying for?</h4>
            <select id="range" name="range" onchange="location = this.options[this.selectedIndex].value;">
                <option value="1">Less than $150,000</option>
                <option value="2">$150,001-$350,000</option>
                <option value="3">$350,000+</option>
            </select>
            <hr>
                <input type="submit" value="Submit" id="process_app" />
            </form>
        </div>
Kishan
  • 1,182
  • 12
  • 26
0

window.location is not working because you are assigning a value to selrange (selrange = '1', selrange = '2') not comparing the value, replace with selrange == '1' ,selrange == '2'

Deepak Mankotia
  • 4,404
  • 6
  • 30
  • 55