Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AbdulBazith's avatar

How to check values returned from controller with javascript values in select box

Guys iam working working with a project job portal site..

i have the education details as javascript (education.js) file.

so in my drop down the education list are displayed from that education.js file.

when education is selected based on that course details are displayed in another drop down from the same js file and when course is selected specialization is is displayed in another dropdown from the same js file.

This is my education.js file



var educationobject = {
    "SSLC": {
        "CBSE": ["English Medium", "Tamil Medium", "Other"],
        "CISCE(ICSE/ISC)": ["English Medium", "Tamil Medium", "Other"],
        "Matriculation": ["English Medium", "Tamil Medium", "Other"],
        "State Board": ["English Medium", "Tamil Medium", "Other"],
        "Other": ["Other"],
    },
    "HSC": {
        "CBSE": ["English Medium", "Tamil Medium", "Other"],
        "CISCE(ICSE/ISC)": ["English Medium", "Tamil Medium", "Other"],
        "State Board": ["English Medium", "Tamil Medium", "Other"],
        "Other": ["Other"],
    },
    "UG/Diploma": {
        "B.A": ["Arts & Humanities ", "Communication", "Economics", "English", "Film", "Fine Arts ", "Hindi", "History", "Journalism", "Pass Course", "Political Science", " PR / Advertising", "Psychology", "Sanskrit", "Sociology", "Statistics", "Vocational Course", "Hotel Management ", "Other"],

        "B.Arch": ["Architecture", "Other"],
        "BCA ": ["Computer Applications", "Other"],
        "B.B.A/B.M.S ": ["Management", "Other"],

        "B.Com ": ["Commerce", "Other"],
        "B.Ed ": ["Education", "Other"],
        "BDS ": ["Dentistry", "Other"],
        "BHM ": ["Hotel Management", "Other"],
        "B.Pharm ": ["Pharmacy", "Other"],
        "B.Sc ": ["Agriculture", "Anthropology", "Bio-Chemistry", "Biology", "Botany", "Chemistry", "Computers", "Dairy Technology", "Electronics", "Environmental science", "Food Technology", "Geology", "Home science", "Maths", "Microbiology", "Nursing", "Physics", "Statistics", "Zoology", "General", "Hospitality and Hotel Management", "Optometry", "Other"],
        "B.Tech/B.E": ["Agriculture", "Automobile", "Aviation", "Bio-Chemistry / Bio-Technology", "Biomedical", "Ceramics", "Chemical", "Civil", "Computers", "Electrical", "Electronics / Telecommunication", "Energy", "Environmental", "Instrumentation", "Marine", "Mechanical", "Metallurgy", "Mineral", "Mining", "Nuclear", "Paint / Oil", "Petroleum", "Plastics", "Production / Industrial", "Textile", "Other"],

        "LLB ": ["Law", "Other"],
        "MBBS ": ["Medicine", "Other"],
        "Diploma ": ["Architecture",
            "Chemical",
            "Civil",
            "Computers",
            "Electrical",
            "Electronics / Telecommunication",
            "Engineering",
            "Export / Import",
            "Fashion Designing / Other Designing",
            "Graphic / Web Designing",
            "Hotel Management",
            "Insurance",
            "Management",
            "Mechanical",
            "Tourism",
            "Visual Arts",
            "Vocational Course",
            "Other",
        ],

        "BVSC ": ["Veterinary Science", "Other"],
        "BAMS ": ["Ayurveda", "Other"],
        "BHMS ": ["Homeopathy", "Other"],
        "B.El.Ed ": ["Elementary Education", "Other"],
        "B.P.Ed ": ["Physical Education", "Other"],
        "B.Des. ": ["Animation Film Design",
            "Ceramic & Glass Design",
            "Exhibition Design",
            "Film and Video Communication",
            "Textile Design",
            "Furniture Design",
            "Product Design",
            "Graphic Design",
        ],
        "BFA ": ["Painting",
            "Sculpture",
            "Art History", "Printmaking", "Visual Communication", "Other"
        ],
        "B.U.M.S ": ["Unani Medicine", "Other"],
        "Other": ["Other"],
    },

    "Maters/PG": {
        "CA": ["CA","Pursuing","First Attempt","Second Attempt","Other"],

        "CS":["CS","Other"],

        "ICWA (CMA)":["ICWA (CMA)","Other"],
        "Integrated PG":["Journalism / Mass Communication","Management","PR / Advertising","Tourism","Other",],
        "LLM":["Law","Other"],
        "M.A":["Anthropology","Arts & Humanities","Communication","Economics","English","Film","Fine arts","Hindi","History","Journalism","Maths","Political Science","PR / Advertising","Psychology","Sanskrit","Sociology","Statistics","Other"],

        "M.Arch":["Architecture","Other"],

        "M.Com":["Commerce","Other"],
        "M.Ed":["Education","Other"],
        "M.Pharma":["Pharmacy","Other"],

        "MS / M.Sc(Science)/M.E":["Agriculture","Anthropology","Bio-Chemistry","Biology","Botany","Chemistry","Computers","Dairy Technology","Electronics","Environmental science","Food Technology","Geology","Home science","Maths","Microbiology","Nursing","Physics","Statistics","Zoology","General","Hospitality and Hotel Management","Optometry","Veterinary Science","Biotechnology","Organic Chemistry","Astronautical Engineering","Aerospace Engineering","Chemical Engineering & Materials","Civil & Environmental Engineering","Electrical Engineering","Industrial & Systems Engineering","Petroleum Engineering","Cyber Security Engineering","Data Informatics","Systems Architecting and Engineering","Mechanical Engineering","Marine Engineering","Electronics & Embedded Technology","Mechatronics","Hospitality Administration","Other",],

        "M.Tech":["Agriculture","Automobile","Aviation","Bio-Chemistry / Bio-Technology","Biomedical","Ceramics","Chemical","Civil","Computers","Electrical","Electronics / Telecommunication","Energy","Environmental","Instrumentation","Marine","Mechanical","Metallurgy","Mineral","Mining","Nuclear","Paint / Oil","Petroleum","Plastics","Production / Industrial","Textile","Other"],

        "MBA / PGDM":["Advertising / Mass Communication","Finance","HR / Industrial Relations","International Business","Information Technology","Marketing","Systems","Other Management","Operations","Hospitality Management","Other"],

        "MCA":["Computers Applications","Other"],

        "Medical-MS / MD":["Cardiology","Dermatology","ENT","General Practitioner","Gyneocology","Hepatology","Immunology","Microbiology","Neonatal","Nephrology","Urology","Obstretrics","Oncology","Opthalmology","Orthopaedic","Other"],

        "PG Diploma":["Chemical","Civil","Computers","Electrical","Electronics","Mechanical","Other",],

        "MVSC":["Veterinary Science","Other"],

        "MCM":["Computers and Management","Other"],

        "MDS":["Dentistry","Other"],

        "MFA":["Sculpture","Printmaking","Visual Communication","Other"],

        "M.Des.":["Animation Film Design","Apparel Design","Ceramic & Glass Design","Design for Retail Experience","Digital Game Design","Film and Video Communication","Furniture Design","Graphic Design","Information Design","Interaction Design","Lifestyle Accessory Design","Other"],

    },

    "Other": {
        "Other": ["Other"],
    },
}
window.onload = function () {
    var education = document.getElementById("education"),
        course_or_board = document.getElementById("course_or_board"),
        specialization_or_medium = document.getElementById("specialization_or_medium");
    for (var edu in educationobject) {
        education.options[education.options.length] = new Option(edu, edu);
    }
    education.onchange = function () {
        course_or_board.length = 1; // remove all options bar first
        specialization_or_medium.length = 1; // remove all options bar first
        if (this.selectedIndex < 1) return; // done
        for (var course in educationobject[this.value]) {
            course_or_board.options[course_or_board.options.length] = new Option(course, course);
        }
    }
    education.onchange(); // reset in case page is reloaded
    course_or_board.onchange = function () {
        specialization_or_medium.length = 1; // remove all options bar first
        if (this.selectedIndex < 1) return; // done
        var special = educationobject[education.value][this.value];
        for (var i = 0; i < special.length; i++) {
            specialization_or_medium.options[specialization_or_medium.options.length] = new Option(special[i], special[i]);
        }
    }
}


actually i have three drop downs.

1st drop down posess SSLC and Other

if SSLC is selected then next dropdown changes to

CBSE,CISCE(ICSE/ISC),Matriculation,State Board these options will be displayed

then if CBSE is selected then the third dropdown changes English Medium, Tamil Medium, Other

this is the loop for that..

education = my first dropdown name

course_or_board= my second dropdown name

specialization_or_medium= my third drop down name

and this is my drop downs in my form

 <select class="form-control capitalize"id="education" name="education" required>
                                <option value="">Select</option>



 <select class="form-control capitalize"  id="course_or_board" name="course_or_board" required>
                            <option value="">Select</option>
                        </select>



<select class="form-control capitalize"  id="specialization_or_medium" name="specialization_or_medium" required>
                            <option value="">Select</option>
                        </select>


Everything works fine.

But the problem is in edit the form.

When i need to fetch the education details from db it is fetching corect and then i placed it in the select box like this

my edit controller

  $education_details_edit = Education_details::find($id);
     
        return view('Edit-seeker-forms.edit-education-details')
        ->withEducation_details_edit($education_details_edit);


and my edit.blade form

 <select class="form-control capitalize"id="education" name="education" required>


                                <option  value='{{$education_details_edit->education}}'>{{$education_details_edit->education}}</option>


                        </select>

and the below mentioned are data returned from controller. which i need to check with the three drop downs.

{{$education_details_edit->education}}  = my controller return which contains education column data

{{$education_details_edit->course_or_board}} =  my controller return which contains course_or_board column data

{{$education_details_edit->specialization_or_medium}} =  my controller return which contains specialization_or_medium column data

but the problem is the value is displayed from controller as well as from javascript also.

say for example if i entered 'SSLC' when i edit this 'SSLC' is displayed in drop down two times.

one from db and another from that education.js file.

Actually in my old project what i did is the drop down details also stored in db, so that i easy checked and eliminated the duplication.

but now the education list is loaded from js file so how can i check.

Kindly some one help please..

Kindly help mee...

0 likes
2 replies
Snapey's avatar
Snapey
Best Answer
Level 122

as mentioned before. iterate over your javascript options and mark it selected if the user data contains the current qualification.

You should not be iterating over the user properties

AbdulBazith's avatar

@snapey thank you for your response.

But can u guide me with small piece of coding .

i dont know howto check with db value with java script values?

please

Please or to participate in this conversation.