简体   繁体   English

jQuery通过传递单击按钮时选择的单选按钮值

[英]Jquery for pass selected radio button value on button click

Am new to JQuery. 是JQuery的新手。 I want to pass the selected radio button values on button click and show that selected radio button values in textboxes and comboboxes. 我想在按钮单击时传递选定的单选按钮值,并在文本框和组合框中显示选定的单选按钮值。

I dont know how it can be done. 我不知道该怎么办。

My current code as follows .displayjobs() displays the table with values in page load. 我当前的代码如下.displayjobs()在页面加载中显示带有值的表。

function displayjobs() {
    $('#jobsTable').empty();
    $("#jobsTable").append("<tr><th>Id</th><th>Operating System</th><th>Browser</th><th>version</th><th>testscript</th><th>server</th></tr>");
    $.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.server);
                    var tabString = '<tr><td>' + value.jobid + '</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" id= ' + value.jobid + 'value=' + value.jobid + '/> </td></tr>';
                    $("#jobsTable").append(tabString);
                });
            }
        }
    });
}

In button onClick showdata()i have to show the selected radio button values to text boxes and comboboxex 在按钮onClick showdata()中,我必须将选定的单选按钮值显示到文本框和comboboxex

<h3>List Jobs</h3>
        <div>
            <h1 style="padding: 10px;">Jobs In Database</h1>
            <div id="jobTable" style="padding-left: 50px;">
                <div style="padding: 5px; padding-left: 0px;">
                    <table id="jobsTable" border="1">
                    </table>
                    <input type="button" id="show" value="showrecord" onclick="showdata();"/>
                </div>
            </div>
            <br/>           
        </div>


<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=""></option>
                            </select>
                        </div>  

                        <div>
                            <label>Versions</label>
                            <select id="version">       
                            </select>
                        </div>  

                        <div>
                            <label>Test Scripts</label>
                            <select id="testscriptlist">
                            <option value=""></option>
                                                    <option value=""></option>
                            </select>
                        </div>  
                        <div>
                            <label>Server:</label>
                            <input type="text" id="server" value="" />
                        </div>

                        <br/>



        </div>      
function showdata(){
 var $tr=$('input:radio:checked').parent().parent(); //will give you the  tr
 var jobid= $tr.find("td:eq(0)").html(); //first td text
 var os= $tr.find("td:eq(1)").html(); //second td text....
 .....
 var server=$tr.find("td:eq(5)").html();

 $("#OS").append("<option value='"+os+"' selected>"+os+"</option>"); //to add an option to select
 $("#server").val(server); //to add value to text box

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM