Solved

jQuery and Repeater

Posted on 2011-03-04
3
681 Views
Last Modified: 2012-05-11
If the user inputs a numeric value into the quantity text box, then I would like to set the price and total textboxes to "0.00"
for that row only.

Please see the screen shot, all the textboxes in all rows changed.
How can I limit it by row?

    $(document).ready(function () {
        $("[id$='_txtQuantity']").blur(function () {
            var quantity = $("[id$='_txtQuantity']").val();
            if (isNumeric(quantity)) {
                $("[id$='_txtPrice']").val('0.00');
                $("[id$='_txtTotal']").val('0.00');
            }
        });
    });

    function isNumeric(n) {
        return !isNaN(parseFloat(n)) && isFinite(n);
    }
 
screen shot
0
Comment
Question by:JRockFL
3 Comments
 
LVL 13

Expert Comment

by:agarwalrahul
ID: 35041572
Please read the documentation:

http://api.jquery.com/val/
0
 
LVL 10

Accepted Solution

by:
P1ST0LPETE earned 500 total points
ID: 35041655
Each row in the repeater should have a unique numeric identifier of some sort.  For example you should have something like:

    _txtQuantity1
    _txtQuantity2
    _txtQuantity3
    etc.....

Then you just need to find the unique identifier (i.e. row index) using javascript.  Then once you have the identifier, you should be able to locate the price and total textboxes fairly easily.  Something like this:

$('[id*="_txtQuantity"]').blur(function ()
{
       var rowIndex = this.id.substring(12, 1);  //should strip out the "_txtQuantity" just leaving the number
       var quantity = $(this).val();
       var price = $('[id*="_txtPrice' + rowIndex + '"]').val();
       $('[id*=_txtTotal' + rowIndex + '"]').val(quantity * price);
});
0
 
LVL 8

Author Closing Comment

by:JRockFL
ID: 35043328
Perfect, thank you
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now