0

i have the option list inside my php code as :

<select class="form-control" name="currentDegree" id="currentDegree">
    <option value="Junior High School">Junior High School</option>
    <option value="Senior High School">Senior High School</option>
    <option value="Diploma">Diploma</option>
    <option value="Bachelor Degree">Bachelor Degree</option>
    <option value="Master">Master</option>
    <option value="Doctor">Doctor</option>
</select>

and then JS tag as

<script>
    var currentDegree = $('#currentDegree').val(); // selected option at listbox
    var minimumDegree = '<php? echo $minimumDegree; ?>'; // it come from the admin backend
    var md; // dinamic variable ( condition depend on minimumDegree )

    function CheckDegree(){                                                                      

        if (minimumDegree == 'Junior High School') {
            md = 0;  
        } else if (minimumDegree == 'Senior High School') {
            md = 1; 
        }
        else if (minimumDegree == 'Diploma') {
            md = 2; 
        }
        else if (minimumDegree == 'Bachelor Degree') {
            md = 3; 
        }
        else if (minimumDegree == 'Master') {
            md = 4; 
        }
        else (minimumDegree == 'Doctor') {
            md = 5; 
        } 
    };
    // Compare the currentDegree variable with External variable
    if (parseint(currentDegree) < md) {
        alert(" Current degree is less than Our minimum requirement !");
        return false;
    }                                                               
</script>  

I use onclick="CheckDegree()" upon submit, But seems it not working properly, has anyone know what type of error in the JS code

Thanks

3 Answers 3

3

Try to use:

var minimumDegree =  '<?php echo $minimumDegree; ?>';

instead of:

var minimumDegree = '<php? echo $minimumDegree; ?>';

You need <?php not <php?

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

Comments

0

you need to move last condition if (parseint(currentDegree) < md) { in the function

check the bottom of this code

function CheckDegree(){                                                                      

    if (minimumDegree == 'Junior High School') {
        md = 0;  
    } else if (minimumDegree == 'Senior High School') {
        md = 1; 
    }
    else if (minimumDegree == 'Diploma') {
        md = 2; 
    }
    else if (minimumDegree == 'Bachelor Degree') {
        md = 3; 
    }
    else if (minimumDegree == 'Master') {
        md = 4; 
    }
    else (minimumDegree == 'Doctor') {
        md = 5; 
    } 

    // Compare the currentDegree variable with External variable
    if (parseint(currentDegree) < md) {
        alert(" Current degree is less than Our minimum requirement !");
        return false;
    }
};

Comments

0

Change this :

'<php echo $minimumDegree; ?>'

For this :

<?php echo $minimumDegree; ?>

Comments

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.