Member_2_1242703
asked on
Getting the value of a label using JavaScript
I have a label on my page called lblActualProductionQuantit y
Inside a repeater, I have 2 textboxes called tbTotalQuantity and tbQuantityPerDisplay.
(I also have a text box inside this repeater called testQty, which ultimately will not be used)
What I'm trying to do is as the user is typing, I want to make tbTotalQuantity (inside repeater) = tbQuantityPerDisplay (inside repeater) times lblActualProductionQuantit y (Outside repeater)
When I run this code, it works fine. All of the controls however are inside the repeater
I want to replace testQty with lblActualProductionQuantit y in my code. Here is what I've tried:
That doesn't work, but I figured the logic would make more sense if I posted it. So how do I get the value of the label lblActualProductionQuantit y which is outside of the repeater?
TIA
Inside a repeater, I have 2 textboxes called tbTotalQuantity and tbQuantityPerDisplay.
(I also have a text box inside this repeater called testQty, which ultimately will not be used)
What I'm trying to do is as the user is typing, I want to make tbTotalQuantity (inside repeater) = tbQuantityPerDisplay (inside repeater) times lblActualProductionQuantit
When I run this code, it works fine. All of the controls however are inside the repeater
<script type="text/javascript">
function closest(elm, className) {
do {
elm = elm.parentNode;
if (elm.className !== undefined && elm.className.indexOf(className) > -1) {
return elm;
}
} while (elm.className !== undefined);
return null;
}
window.populate_num = function populate_num(elm) {
var dm = closest(elm.parentElement, 'entry');
dm.getElementsByClassName("tbTotalQunatity")[0].value = dm.getElementsByClassName("tbQtyPerDisplay")[0].value * dm.getElementsByClassName("testQty")[0].value;
}
</script>
I want to replace testQty with lblActualProductionQuantit
<script type="text/javascript">
function closest(elm, className) {
do {
elm = elm.parentNode;
if (elm.className !== undefined && elm.className.indexOf(className) > -1) {
return elm;
}
} while (elm.className !== undefined);
return null;
}
window.populate_num = function populate_num(elm) {
var dm = closest(elm.parentElement, 'entry');
dm.getElementsByClassName("tbTotalQunatity")[0].value = dm.getElementsByClassName("tbQtyPerDisplay")[0].value * document.getElementById("lblActualProductionQuantity").value;
}
</script>
That doesn't work, but I figured the logic would make more sense if I posted it. So how do I get the value of the label lblActualProductionQuantit
TIA
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I was not provided with a working solution and was able to figure it out.
You could continue to use class names or in your javascript you can use the asp.net control name to get the client ID.
Code example (not mine) can be found at http://www.codeproject.com/Tips/578580/How-to-Get-User-Controls-ClientID-in-JavaScript-in
VB code:
Open in new window
Javascript example:
Open in new window