开发者

multiple input fields on text change

We are working on a large for开发者_开发技巧m and there is 1 option for selecting installments for user, so we are using form select to show duration like 6 12 18 24 30 36 and it should give 6 boxes if admin selects 6 with 2 input fields DATE and Amount after that it should be saved to mysql using php, so can you give some advice or code please? thanks...


@seopps AFAIU you want a raw format, how to develope a form and proceed further, i m giving u just a hint, you can manipulate/modify according to your need

installment.php

<script type="text/javascript">
$(document).ready(function(){
    $('select').change(function () {
        $('div#wayofpay').show();
    });
});
</script>



<form method="post" action="nextpage.php">
    <select name="installment" id="installment">
        <option value=''>Select Duration:</option>
        <?php foreach(range(0,36,6) as $ts) { ?>
        <option value='<?php echo $ts?>'><?php echo $ts;?></option>
        <?php } ?>
    </select>

    <div id="wayofpay" style="display:none">
    <label for='start_date'>Date:</label><input type="text" name="start_date" id="start_date" value="">
    <label for='amount'>Amount:</label><input type="text" name="amount" id="amount" value="">
    </div>
</form>

nextpage.php

$post_data = array_map('mysql_real_escape_string',$_POST);
// create mysql connection and use below query

$qry= "INSERT INTO yourtable SET
                                  installment_duration = $post_data['installment'];
                                  start_date=$post_data['start_date'];
                                  amount =$post_data['amount'] ";
mysql_query($qry);


For the client side you can use the below jQuery script Working example here

Enter Duration: <input type="text" id="duration" />
<button>Go</button><br />
<form id="orders">
</form>

And the javascript..

<script>
$('button').click(function(){
    var count = parseInt($('#duration').val(), 10);
    if(!isNaN(count)){
        for(i=1;i<=count;i++){
            $('#orders').append(i+". ").append("<input class='item' /><br />");
        }
       }
});
</script>

For the MySQL php part there are numerous examples available out there and a little googling will certainly help.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜