Changing Image Based On Selection In 2 Dropdowns June 09, 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 Edit A Txt File Using Javascript/jquery I want to modify a .txt (overwrite completely) using javasc… How To Include Highcharts Motion Plugin For Bubble Plot Using R Wrapper? Highcharts motion plugin - Requires 3 adjustments to a high… Using A Jquery Slider For Text Instead Of Images? This may be a little too specific, but I have a jquery slid… Detect Child Node Number I'm trying to add a event listener for clicking and I w… Fade In Fade Out Using Dynamic Range Input Speed And Repeat am Trying to control the speed and repeat of my fade in fad… Genvalidator: Check For Checkbox In Form Validation I'm using genvalidator to have some tests on input fiel… Text-overflow Ellipsis Without "white-space: Nowrap"? I was wondering if there is any clever way, to achieve the … How To Handle 'Possibly Unhandled Rejection: Backdrop Click' In A General Way I have an angular service for handling modals: angular.modu… Call Multiple Ajax Request In Series Or Parallel I have 3 functions. load_graphs('national','… Axios - How To Deal With Big Integers Here is my request: axios.get(url) .then(res => … December 2024 (1) November 2024 (37) October 2024 (60) September 2024 (18) August 2024 (382) July 2024 (342) June 2024 (695) May 2024 (1295) April 2024 (805) March 2024 (1554) February 2024 (1686) January 2024 (1347) December 2023 (1310) November 2023 (414) October 2023 (567) September 2023 (315) August 2023 (341) July 2023 (278) June 2023 (374) May 2023 (204) April 2023 (124) March 2023 (136) February 2023 (187) January 2023 (261) December 2022 (123) November 2022 (224) October 2022 (150) September 2022 (164) August 2022 (488) July 2022 (285) June 2022 (263) Menu Halaman Statis Beranda © 2022 - JavaScript College