Changing Image Based On Selection In 2 Dropdowns March 12, 2024 Post a Comment I have two select elements: ab<Solution 1: You need to write a function which is called on the change event of both select elements which concatenates the image filename and updates the src property of the required img, something like this:$('select.form-control').change(function() { var filename = $('#shape').val() + '-' + $('#waist').val() + '.jpg'; $('#imgToChange').prop('src', filename); }); CopySolution 2: You can use this to get the combined value of dropdowns in the format like a-2,a-3,b-1 etc.document.getElementById("shape").value + "-" + document.getElementById("waist").valueCopySolution 3: you can use the below plunker as well.https://plnkr.co/edit/1P12J0Ahl2S1m6aJ1rD0?p=preview<selectclass="form-control"id="shape"name="shape"><optionvalue=""></option><optionvalue="a">a</option><optionvalue="b">b</option><optionvalue="c">c</option><optionvalue="d">d</option><optionvalue="e">e</option><optionvalue="f">f</option></select><selectclass="form-control"id="waist"name="waist"><optionvalue=""></option><optionvalue="1">1</option><optionvalue="2">2</option><optionvalue="3">3</option></select><buttononClick="test()">Proceed</button>Copyin script.var test = function(){ if($("#shape").val() != "" && $("#waist").val() != "") { alert("Update"); } else { alert("select both the option"); } }; Copyhere each select box has the default blank option and if user try to proceed then the value is checked and appropriate message is displayed.Solution 4: You can use a solution with jQuery (javascript) / PHP / AJAX (and don't worry, AJAX is easy). It will work like this:jQuery - detect when both SELECT controls have been changed, AJAX - a jQuery block that sends data to a back-end PHP file, PHP - Receives AJAXed data and identifies the correct image (e.g. from MySQL) then builds HTML code and ECHOs it back to jQuery side, AJAX - Receives PHP data via AJAX, jQuery - Inside the AJAX success function, uses the ,html() method to insert the new HTML into the DOMThat's the overview. Here's how it will look code-wise:HTML:<selectclass="form-control"id="shape"name="shape"><optionvalue="">Options go here</option></select><selectclass="form-control"id="waist"name="waist"><optionvalue="">Options go here</option></select><divid="someDIV"> //DIV that will receive IMG tag </div>CopyjQuery:var chg = false; $('#shape, #waist').change(function(){ if (!chg){ chg=true; }else{ var myimg = $('#shape').val() + $('#waist').val(); $.ajax({ type: 'post', url: 'my_second_php_file.php', data: 'myimg=' +myimg, success: function(d){ //if (d.length) alert(d); $('#someDIV').html(d); } }); //END AJAX }//end else }); //END select.changeCopyPHP:<?php$img = $_POST['myimg']; //echo ($img); die();//$result = Do your MySQL lookup here$out = ' <img src="' .$result['img']. '" class="yourImage" /> '; echo$out; ?>CopyHere is a jsFiddle DEMO that approximates how it will work. jsFiddle cannot do AJAX, so the AJAX routine is replaced by something that will demonstrate how it will look, rather than a true working example.Here are some simple demos of AJAX code and a brief explanation -- copy them to your own system and experiment. Really quite simple, and xtreme useful.Here are some free, 10-min video mini-tuts on AJAX. Share Post a Comment for "Changing Image Based On Selection In 2 Dropdowns" Top Question Select Element Onmouseleave Event In Safari I want to catch the mouse leaving a select box with the cod… How To Dynamically Add An New Input Field On "keydown" Using JQuery? I want to have a new input field dynamically generated when… Input Type Datetime-local Is Not Working In Firefox I have an input type of datetime-local which is working fin… Block Scoping Of Let And For…of The let statement in ES2015 allows us to declare block scop… Reference Errors Thrown In Included File... Unless Calling File Includes Slow Code A funny thing happened to me while I was cleaning up some o… Getting Object Name From Inside The Class (JavaScript) I have a class and I want from inside the class to save as … Cannot Read Property 'getContext' Of Null I have a button which on click executes this function.This … What Are Alternatives To ExtJS? So what I'm looking for is a javascript framework I can… How Do I Use Data From Vue.js Child Component Within Parent Component? I have a form component where I use a child component. I wa… Link External JS File To Prestashop I'm creating a custom module in Prestashop 1.7, and I&#… December 2024 (1) November 2024 (37) October 2024 (70) September 2024 (23) August 2024 (367) July 2024 (334) June 2024 (701) May 2024 (1297) April 2024 (807) March 2024 (1552) February 2024 (1717) January 2024 (1373) December 2023 (1452) November 2023 (421) October 2023 (593) September 2023 (302) August 2023 (343) July 2023 (270) June 2023 (370) May 2023 (215) April 2023 (132) March 2023 (152) February 2023 (181) January 2023 (286) December 2022 (131) November 2022 (239) October 2022 (164) September 2022 (169) August 2022 (505) July 2022 (313) June 2022 (269) Menu Halaman Statis Beranda © 2022 - JavaScript Gen