doutong1890 2016-05-16 03:56
浏览 39

如何设置值来输入文本框jquery

I have a table with a text box column and I want to get the old value and set it to the text box onchange.

        <span class="txt_b">
            <input type="number" name="" value="<?php echo $req; ?>" onchange="onChangeTest(this)" onchange="setoldvalue(this)" oldvalue="" class="input_md radious_all innershadow padding_control" id ="tk" style="width:60px;" id="qty_req_<?php echo $i; ?>" onblur="editBucket('<?php echo $row_id; ?>','<?php echo $item['Item']['code']; ?>',$('#qty_war_<?php echo $i; ?>').val(),this.value,'<?php echo $date; ?>',$('#stock_notes_<?php echo $i; ?>').val(),'<?php echo $item['Item']['pack_size']; ?>')"/>
        </span>
    </div>
    <input type="hidden" name="product" id="qty_reqty_" class="product" value="qty_reqty_<?php echo $i; ?>" />
</div>
<script> 
    function getoldvalue()
        {
            $('input').on('focusin', function(){
                console.log("Saving value " + $(this).val());
                $(this).data('val', $(this).val());
            });

            $('input').on('change', function(){
                var prev = $(this).data('val');
                $('input').val(prev);
                console.log(s);
                var current = $(this).val();
                console.log("Prev value " + prev);
                console.log("New value " + current);
            });

I am struggling with setting the value to the text box. How to it by id?

this is my jquery dialogbox

function editCart(id,code,stock_wh,stock_rq,date,notes,pack){

if((stock_rq%pack) != 0){

    $('<div></div>').appendTo('body')
  .html('<div id="dialog"><h3>The quantity should be multiple of pack size, do you wish to continue with the quantity entered?</h3></div>')
    .dialog({
    modal: true,
    title: 'message',
    zIndex: 10000,
    autoOpen: true,
    width: 'auto',
    resizable: true,
    buttons: {

    Yes: function () {
            doFunctionForYes();
            $(this).dialog("close");
        },

     No: function () {
            doFunctionForNo();

            $(this).dialog("close");
        }
    },

    close: function (event, ui) {
        $(this).remove();
    }
});
$('#msg').hide();

function doFunctionForYes() {

   $('#msg').show();

}
function doFunctionForNo() {
alert("doFunctionForNo");

     });

} 

}
  • 写回答

2条回答 默认 最新

  • douwen3500 2016-05-16 04:14
    关注

    you have some issue on defining html:

    1. can not have 2 id attribute for one input
    2. can not have 2 onchange on input
    3. oldvalue is not standard attribute

    you can set data-oldvalue attribute to your input and access that with jQuery

    <input type="text" id="qty_req_<?php echo $i; ?>" data-oldvalue="<?php echo $req; ?>" />
    
    <script>
    $( document ).ready(function() {
         oldvalue = $("#qty_req_<?php echo $i; ?>").data('oldvalue');
    });
    </script>
    

    the jquery code is for sample and you can use from this code everywhere which you need

    评论

报告相同问题?

悬赏问题

  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
  • ¥50 invest生境质量模块