views:

21

answers:

3

II am working website which is going to be accessed by a motorola device(scanner) but the functionality needs to be same a normal/usual website. On one of the page I have a textbox -> productID and listbox which can have multiple productID. Now when the focus is on textbox and it scans the productID ,the scanner returns a tab,now after this happens I need to add the textbox value to the listbox and empty the textbox and set focus on the textbox. I also should be able to delete a productId from the list.How can I achieve this using Jquery?

<table style=" width:220px;">
        <tr>
            <td style=" width:120px;">cost</td>
            <td style=" width:100px;"><asp:TextBox ID="txt_cost" runat="server"></asp:TextBox></td>
        </tr>
        <tr>
            <td style=" width:120px;">Product ID</td>
            <td style=" width:100px;"><asp:TextBox ID="txt_ProdID" runat="server"></asp:TextBox></td>
        </tr>
        <tr>
            <td style=" width:120px;">List of ProductID</td>
            <td style=" width:100px;"><asp:ListBox ID="lst_ProductId" runat="server"></asp:ListBox> </td>
        </tr>
        <tr>
            <td style=" width:120px;"><asp:Button ID="btn_Update" runat="server" Text="Update" /></td>
            <td style=" width:100px;"><asp:Button ID="btn_Remove" runat="server" Text="Remove" /></td>
        </tr>
    </table>
A: 
$('#lst_ProductId').append($('#txt_ProdID').val());
$('#txt_ProdID').val('');
$('#txt_ProdID').focus();

Something like that should work.

Gazler
A: 
$('#lst_ProductId').append($('#txt_ProdID').val()); <- set  value
$('#txt_ProdID').val('');-> clrs textbox
$('#txt_ProdID').focus();->focus
 $('#lst_ProductId').remove($this); ->removes

pls use blur() when pressing tabs

Vishnu K B
A: 
$(function() {
            $('[id$=txt_ProdID]').keydown(function(event) {
                {                
                    if(event.keyCode == 9)
                    {
                       var textboxval = $('#txt_ProdID').val();
                       var lsOptNew =  document.createElement('option');
                       lsOptNew.text = textboxval;
                       lsOptNew.value = textboxval;
                       var lsProdID = document.getElementById('lst_ProdId');
                       try
                       {
                            lsProdID.add(lsOptNew,null);
                       }
                       catch(ex)
                       {
                          lsProdID.add(lsOptNew);
                       }                             


                        $('[id$=txt_ProdID]').val('');
                        $('[id$=txt_ProdID]').focus();                       

                    }
                    }
                });
        });
Pinu