如何在使用jQuery进行编辑时设置单选按钮的值? [英] How to set the value for radio button while editing using jQuery?
问题描述
我的表单中有一个单选按钮,当我输入参考号时,我可以使用 jQuery 获取相应的表单详细信息以及 source 值。我不知道如何将该值设置为单选按钮。
< input type =radiong-model =selectedname =sourceclass = source<?php echo($ row ['source'] =='VAT')?'checked':''?> value =VAT> VAT
< input type =radiong-model =selectedname =sourceclass =source<?php echo($ row ['source'] =='CST')?'checked':''?> value =CST> CST
post_process.php 所选单选按钮的值可以这样做: 当你从ajax调用得到响应时,检查你的按钮:首先改变它: 您返回的值为 I've a radio button in my form and when I enter a reference number, I can fetch the corresponding form details along with source value using jQuery. I don't know how to set that value to radio button. Thank You! jQuery post_process.php
If you are looking to get the value of a selected radio button you can do this: When you get the response from your ajax call you check your button: First change this: This assune that your returned value is 这篇关于如何在使用jQuery进行编辑时设置单选按钮的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
('keypress',function(e){
if(e.keyCode === 13)
{pre $('#gp_no')。
$(this).trigger(enterKey);
var val = $(this).val();
var dataString =gp_no =+ val;
$ .ajax({
type:POST,
url:post_process.php,
data:dataString,
dataType:'json',
成功:function(data){
$('。source').val(data.source);
}
});
}
});
if(ISSET($ _ POST ['gp_no'])){
$ gp_no = $ con> real_escape_string($ _ POST ['gp_no']);
$ query =SELECT * FROM items WHERE items.gp_no = $ gp_no;
$ b $ if($ result = $ con> query($ query)){
$ row = $ result-> fetch_assoc();
$ source = $ row ['source'];
}
$ json = array($ vehicle_no,'source'=> $ source);
$ json = json_encode($ json);
echo $ json;
$('input [name =source]:checked' ).val()
< input type =radiong -model =selectedname =sourceclass =sourceid =VATvalue =VAT> VAT
< input type =radiong-model =selectedname = sourceclass =sourceid =CSTvalue =CST> CST
$(#+ data.source).prop(checked,true)
VAT
或 CST
<input type="radio" ng-model="selected" name="source" class="source" <?php echo ($row['source']=='VAT')?'checked':'' ?> value="VAT">VAT
<input type="radio" ng-model="selected" name="source" class="source" <?php echo ($row['source']=='CST')?'checked':'' ?> value="CST">CST
$('#gp_no').on('keypress', function(e){
if(e.keyCode === 13)
{
$(this).trigger("enterKey");
var val = $(this).val();
var dataString = "gp_no=" + val;
$.ajax({
type: "POST",
url: "post_process.php",
data: dataString,
dataType: 'json',
success: function(data){
$('.source').val(data.source);
}
});
}
});
if(ISSET($_POST['gp_no'])) {
$gp_no = $con->real_escape_string($_POST['gp_no']);
$query = "SELECT * FROM items WHERE items.gp_no = $gp_no";
if ($result = $con->query($query)) {
$row = $result->fetch_assoc();
$source = $row['source'];
}
$json = array($vehicle_no, 'source' => $source);
$json = json_encode($json);
echo $json;
}
$('input[name="source"]:checked').val()
<input type="radio" ng-model="selected" name="source" class="source" id="VAT" value="VAT">VAT
<input type="radio" ng-model="selected" name="source" class="source" id="CST" value="CST">CST
$("#"+data.source).prop("checked", true)
VAT
or CST