如何在javascript或ajax中获取输入单选按钮值并显示/隐藏按钮

时间:2016-03-30 05:03:34

标签: javascript php jquery ajax

我有一个带有以下输入按钮的表单:

<input type="radio" value="2" id="order_status"> Review
<input type="radio" value="1" id="order_status"> Accept
<input type="radio" value="2" id="order_status"> Decline
<input type="radio" value="3" id="order_status"> Refund


<textarea id="remarks"> </textarea>
<input type ="button" value="Update" id="updateBtn" name="updateBtn"onclick="submitForm2()">

我想要做的是获取单选按钮的值,如果是2 textarea(注释)不应为空。因此更新按钮不应该是可提交的,否则,如果单选按钮的值为0或1,则备注可能为空,也可能不为空,提交按钮也应该有效... 怎么做,请有人解释一下......

function submitForm2()
{
var remarkVal = $("#remarks").val();
var remark = $("#remarks").val().length;
var order_status = $('form input:checked').attr('value');

if(order_status== 2 || order_status == 3){
    if(remark < 15){
    //alert("Please Fill The Remarks Field");
    return false;
alert(remarkA);
}
else if(remark > 15){
    return true;
}
else 
{

    $.ajax({
      url:"orderStatusUpdate.php",  
      type:"GET",
    //  data:"order_status="+order_status+"&id="+<?php echo $id; ?>+"&uid="+<?php echo $uid;?>, <?php echo $edited_by;?>

     data:"order_status="+order_status+"&remarks="+remarkVal+"&id="+<?php echo $id; ?>+"&uid="+<?php echo $uid;?>, <?php echo $edited_by;?>

      success:function(content) {
      history.go(1);
      }
   });
}
}

1 个答案:

答案 0 :(得分:0)

试试这个:

<!DOCTYPE html>
<html>
    <head>
    </head> 
    <body>
       <input type="radio" value="2"> Review
        <input type="radio" value="1"> Accept
        <input type="radio" value="2"> Decline
        <input type="radio" value="3"> Refund
        <textarea id="remarks"> </textarea>
        <input type ="button" value="Update" id="updateBtn" name="updateBtn"onclick="submitForm2()">

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
    <script type="text/javascript">
        function submitForm2()
        {
            var remarkVal = $("#remarks").val();
            var remark = $("#remarks").val().length;
            var order_status = $('input:checked').val();

            if(order_status== 2 || order_status == 3){
                if(remark < 15 || remark == ''){
                    alert("Please Fill The Remarks Field");
                    return false;
                } else if(remark > 15){
                    return true;
                }
           } else {
                $.ajax({
                    url:"orderStatusUpdate.php",
                    type:"GET",
                    data:"order_status="+order_status+"&remarks="+remarkVal+"&id="+'<?php echo $id; ?>'+"&uid="+'<?php echo $uid;?>'+'<?php echo $edited_by;?>',
                    success:function(content) {
                        history.go(1);
                    }
               });
            }
        }
    </script>
</body>
</html>

希望这会对你有所帮助! :)