JQuery code to change selectable dropdown menu options based on radio button selection

How can I change selectable dropdown menu options based on switch selection. here am code is used with

HTML:

<div id="manage"> <div> <label>Operating Systems</label> <select id="OS" onchange="browserlist();"> <option value="win7 32">Windows 7 - 32</option> <option value="win7 64">Windows 7 - 64</option> <option value="Vista 32">Windows Vista - 32</option> <option value="Vista 64">Windows Vista - 64</option> <option value="Win8 X64">Windows 8 - X64</option> </select> </div> <div> <label>Browsers</label> <select id="browsers" onchange="browserDet();"> <option value="ie">IE</option> <option value="vista">Vista</option> </select> </div> <div> <label>Versions</label> <select id="version"></select> </div> <div> <label>Test Scripts</label> <select id="testscriptlist"> <option value="1">test1</option> <option value="2">test2</option> <option value="3">test3</option> <option value="4">test34</option> </select> </div> <div> <label>Server:</label> <input type="text" id="server" value="" /> </div> 

JavaScript:

 $.ajax({ type: 'GET', url: "/getJobs", dataType: "json", success: function (jobs) { //alert(jobs); if (jobs.length == 0) { alert("There are no scheduled Jobs"); $("#jobsTable").hide(); } else { //jobs.forEach(function(job) { $.each(jobs, function (key, value) { alert(value.jobid); var tabString = '<tr><td>' + value._id + '</td><td>' + value.os + '</td><td>' + value.browser + '</td><td>' + value.version + '</td><td>' + value.script + '</td><td>' + value.server + '</td><td>' + '<input type="radio" name="joblist" onclick="myfunc(this);" id= ' + value.jobid + 'value=' + value.jobid + '/> </td></tr>'; $("#jobsTable").append(tabString); }); } } }); } 

The following code is used in onclick radio buttons. When choosing a switch, I get the values ​​of the radio button and you will need to change the selectable options for the drop-down menu based on the choice of the switch.

 function myfunc(ele) { var $tr = $(ele).parent().parent(); var os = $tr.find("td:eq(1)").html(); var browsers = $tr.find("td:eq(2)").html(); var version = $tr.find("td:eq(3)").html(); var testscriptlist = $tr.find("td:eq(4)").html(); var server = $tr.find("td:eq(5)").html(); } 
+4
source share
1 answer

Your question is a bit unclear, but from your code, I assume that you want to select specific values ​​for the drop-down lists after selecting the radio button.

jQuery.val () is what you want.

 function myfunc(ele) { var $tr = $(ele).parent().parent(); var os = $tr.find("td:eq(1)").html(); var browsers = $tr.find("td:eq(2)").html(); var version = $tr.find("td:eq(3)").html(); var testscriptlist = $tr.find("td:eq(4)").html(); var server = $tr.find("td:eq(5)").html(); $("#OS").val(os); $("#browsers").val(browsers); $("#version").val(version); $("#testscriptlist").val(version); $("#server").val(server); } 
0
source

Source: https://habr.com/ru/post/1498888/


All Articles