douzhan8303 2011-05-11 07:29
浏览 74
已采纳

如果从数据库中检查单选按钮值,如何显示文本框?

I have 3 radio buttons

<input  type="radio" name="preferedpaymt" value="CheckMailed" id="CheckMailed1" <?php if($paymnt=="CheckMail") {?> checked="checked" <?php }?> />
(a)Check Mailed

<input  type="radio" name="preferedpaymt" value="PayPal"  <?php if($paymnt=="PayPal") {?> checked="checked" <?php }?> />
(b)By PayPal

<input  type="radio" name="preferedpaymt" value="WireTransfer"  id="WireTransfer" <?php if($paymnt=="wireTransfer") {?> checked="checked" <?php }?> />
(c)Wire Transfer To Bank A/c$12

But the value of radiobutton is checked from database . With these 2 tables are associated if Radiobutton 2 is checked table1 1 should populate id tb1

here the problem is when a value of radio button is checked from database the table does not get populate if you only click it gets populated i want it automatis how can i do it?

jquery code, which I am using

<script type="text/javascript">
jQuery(function () {
    jQuery("input[name=preferedpaymt]").change(function () {
        if ($(this).val() == "PayPal") {
            jQuery("#ppl").slideDown()
        } else {
            jQuery("#ppl").slideUp();
        }
    });
});
</script>
  • 写回答

1条回答 默认 最新

  • dongsi4547 2011-05-11 07:47
    关注

    Or you culd use:

    var chk_val = jQuery("input[name='preferedpaymt']:checked").val();
    alert(chk_val);
    

    EDIT: how to use it!

    Your inputs:

    <input  type="radio" name="preferedpaymt" value="CheckMailed" id="CheckMailed1" <?php if($paymnt=="CheckMail") {?> checked="checked" <?php }?> />
    (a)Check Mailed
    
    <input  type="radio" name="preferedpaymt" value="PayPal"  <?php if($paymnt=="PayPal") {?> checked="checked" <?php }?> />
    (b)By PayPal
    
    <input  type="radio" name="preferedpaymt" value="WireTransfer"  id="WireTransfer" <?php if($paymnt=="wireTransfer") {?> checked="checked" <?php }?> />
    (c)Wire Transfer To Bank A/c$12
    

    Then lets say you got one tables for each payment choise. ex:

    NOTE All tables has the same classname this is because i want to hide all of them by default. The id attribute is set to "table_paymentmethod".

    <table class="payment_table" id="table_CheckMailed" height="200" bgcolor="#00FF33" width="100px;" >
    <tr>
      <td>
    
         You checked Checked mail
      </td>
    </tr>
    </table>
    
    <table class="payment_table" id="table_PayPal" height="200" bgcolor="#FF0000" width="100px;" >
    <tr>
      <td>
    
         You checked Paypal
      </td>
    </tr>
    </table>
    
    <table class="payment_table" id="table_WireTransfer" height="200" bgcolor="#CCC" width="100px;" >
    <tr>
      <td>
    
         You checked wiretransfer
    
      </td>
    </tr>
    </table>
    

    Now to the part where jquery comes in handy.

    <script type="text/javascript">
     jQuery(document).ready(function(){
            jQuery('.payment_table').hide(); // Hide all tables by default
    
            var chk_val = jQuery("input[name='preferedpaymt']:checked").val(); // Grab the value of the selected radio
    
            jQuery('#table_'+chk_val).slideDown(1000); // Slides down the right table on page load.
      });
    </script>
    

    Well there you go, should do the trick for you. Im not the best at explaining but it should be pretty straightforward.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 怎样才能让鼠标沿着线条的中心线轨迹移动
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?