0

I have the following code in mypage,

    ....
    <input type="checkbox" title="Warehouse1" name="warehouse[]" id="selectedUser_1" class="select_checkbox" rel="warhouse_1" value="23">
    <input type="checkbox" title="Warehouse2" name="warehouse[]" id="selectedUser_2" class="select_checkbox" rel="warhouse_2" value="24">
    .....
    //text box to enter current stock for the above warehouses
    <input type="text" style="" name="current_stock[]" value="10" id="current_st_1" class="validtxt">
    <input type="text" style="" name="current_stock[]" value="11" id="current_st_2" class="validtxt">
    .....
<input type="button" id="check_warehouse_qty" name="check_warehouse_qty" value="OK">

Here when i click button i need to store repective checkbox value with textbox . for example i need to get 23_10,24_11 . so that i can assign in hidden textbox and do further manipulation. kindly advice on this.

4 Answers 4

3

You'd want to do something like this:

$('#check_warehouse_qty').click(function() {

    $('.select_checkbox').each(function() {

        var val = $(this).val();  // "23"

        var id = $(this).attr('id').replace('selectedUser_', '');

        val += $('#current_st_' + id).val(); // "23_10"

        // store 'val' in some hidden field
        $('hidden_field_' + id).val(val);

    });

});
Sign up to request clarification or add additional context in comments.

Comments

0

I'm not sure I understand how you want to move your values around but here's a shot.

You can set the value of a form field with:

$('#inputId').val(newVal);

So in your case something like this would move the current_st_1 value to the selectedUser_1 value:

$('#selectedUser_1').val($('#current_st_1').val());

If you want to concatenate the values you can use:

$('#selectedUser_1').val($('#selectedUser_1').val() + '_' + $('#current_st_1').val());

Here is a link to the jQuery API docs for the val() function: http://api.jquery.com/val/

Comments

0

To get/set the value you should be able to use .val(), for example, something like:

$('#current_st_1').val($('#selectedUser_1').val());

Comments

0

I think you need something like this

<script type="text/javascript">
(function($) {
    $(function() {
        $('#check_warehouse_qty').click(function(e){

            //check if first checkbox is ticked
            if ($('#selectedUser_1').attr('checked')) {
                //checks if value was already put in
                if($('#current_st_1').val().indexOf($('#selectedUser_1').val()+'_') == -1){
                    //if it was not then set the value
                    $('#current_st_1').val($('#selectedUser_1').val()+'_'+$('#current_st_1').val());
                }
            }
            else{
                //remove value if unchecked
                $('#current_st_1').val($('#current_st_1').val().replace($('#selectedUser_1').val()+'_',''));
            }

            //check if second checkbox is ticked
            if ($('#selectedUser_2').attr('checked')) {
                //checks if value was already put in
                if($('#current_st_2').val().indexOf($('#selectedUser_2').val()+'_') == -1){
                    //if it was not then set the value
                    $('#current_st_2').val($('#selectedUser_2').val()+'_'+$('#current_st_2').val());
                }
            }
            else{
                //remove value if unchecked
                $('#current_st_2').val($('#current_st_2').val().replace($('#selectedUser_2').val()+'_',''));
            }
        });
    });
})(jQuery);
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.