开发者

how to show textbox if radio button value is checked from database?

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"开发者_如何学Go) {
            jQuery("#ppl").slideDown()
        } else {
            jQuery("#ppl").slideUp();
        }
    });
});
</script>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜