i have a multiple textboxes in repeater and i will enter value in those textboxes at runtime. and i want sum of all value entered in those textboxes in one label.i want to do this thing using java script. so can u please help me.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here is one idea to get you started:
<div>around yourRepeaterand give it a uniqueid.document.getElementById()function in JavaScript to obtain a reference to that<div>.getElementsByTagName()function in the DOM element to find all<input>s within.So if your markup looks something like this:
The JavaScript looks approximately like this:
Now, this code does not check to ensure that the
<input>s are actually oftype=textor to confirm that the entered values are numbers. Those parts are left as exercises for the reader 😉Edit: If you have multiple text boxes in each “line” outputted by the
Repeaterand you only want to sum the values for one “group” of boxes, you will need to change the script a bit. Here are two possible solutions – pick one:If you know exactly how many
<input>elements you have in each “line”, you can change theforloop in the client script to only visit every Nth element. Eg. to select only the last of three fields in each line:for (var i = 2; i < inputs.length; i += 3)Change your markup to include a
classattribute on the<input>elements to be part of the sum. Within theforloop, do a test oninputs[i].classNameto verify if the particular field is to be included.