Changing Image Based On Selection In 2 Dropdowns December 11, 2023 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 How To Validate Form Fields And Post The Form Data To Server Using Jquery And Ajax? I am trying to validate form fields like, Name (must not be… Replace Url From Youtube To Embed Code - Error: Permission Denied To Access Property 'toString' I have this code and this error in FireBug: Error: Permiss… How To Add Date Time Value To Input By Onclick Checked JQuery i have this Solution 1: jsFiddle Demo var months = n… External API GET() Request Using JQuery I am using the IMDb API v2.0 located here and I decided to … JQuery - Renaming Checkboxes Sets Consecutively I'm trying to build a form to allow multiple elements (… Dropdown Menu On Refresh Changes Javascript I have implemented a navbar uisng bootstrap 4,in which I ha… 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… Uncaught TypeError: $(...).tooltipster Is Not A Function I can't use the tooltipster library along with tablesor… How Do Libraries/programming Languages Convert Floats To Strings This is a mystery that I was trying to figure out when I wa… Save Last Session Of Chrome Extension In my html file I have a simple table and a couple of butto… December 2024 (1) November 2024 (35) October 2024 (68) September 2024 (25) August 2024 (371) July 2024 (334) June 2024 (705) May 2024 (1290) April 2024 (788) March 2024 (1543) February 2024 (1653) January 2024 (1323) December 2023 (1379) November 2023 (392) October 2023 (493) September 2023 (299) August 2023 (352) July 2023 (269) June 2023 (351) May 2023 (209) April 2023 (127) March 2023 (150) February 2023 (182) January 2023 (282) December 2022 (132) November 2022 (230) October 2022 (172) September 2022 (170) August 2022 (496) July 2022 (303) June 2022 (266) Menu Halaman Statis Beranda © 2022 - JavaScript OfficialSite