fwstealer
asked on
set label value with javascript
i can get everything but the setting of the label.
function TotalUsedShares07()
{
var _txtBox1 = document.getElementById('< %= txtbx07d.ClientID %>').value;
var _txtBox2 = document.getElementById('< %= txtbx07e.ClientID %>').value;
var _txtBox3 = document.getElementById('< %= txtbx07f.ClientID %>').value;
var value1 = _txtBox1;
var value2 = _txtBox2;
var value3 = _txtBox3;
document.getElementById('< %=lbl07g.C lientID %>').value = parseFloat(value1) + parseFloat(value2) + parseFloat(value3);
}
function TotalUsedShares07()
{
var _txtBox1 = document.getElementById('<
var _txtBox2 = document.getElementById('<
var _txtBox3 = document.getElementById('<
var value1 = _txtBox1;
var value2 = _txtBox2;
var value3 = _txtBox3;
document.getElementById('<
}
ASKER
its in a form - part of a table; i tried the following:
function TotalUsedShares07()
{
var _txtBox1 = document.getElementById('< %= txtbx07d.ClientID %>').value;
var _txtBox2 = document.getElementById('< %= txtbx07e.ClientID %>').value;
var _txtBox3 = document.getElementById('< %= txtbx07f.ClientID %>').value;
var value1 = _txtBox1;
var value2 = _txtBox2;
var value3 = _txtBox3;
var valSum = parseFloat(value1) + parseFloat(value2) + parseFloat(value3)
alert(valSum);
var elMyElement = document.getElementById('< %= lbl07g.ClientID %>').value;
alert(elMyElement); //returns nothing
document.getElementById("l bl07g").in nerHTML = valSum; //fails setting value
alert(document.getElementB yId('<%= lbl07g.ClientID %>').value);
//elMyElement.innerHTML = valSum;
//document.getElementById( '<%=lbl07g .ClientID %>').value = valSum;
}
function TotalUsedShares07()
{
var _txtBox1 = document.getElementById('<
var _txtBox2 = document.getElementById('<
var _txtBox3 = document.getElementById('<
var value1 = _txtBox1;
var value2 = _txtBox2;
var value3 = _txtBox3;
var valSum = parseFloat(value1) + parseFloat(value2) + parseFloat(value3)
alert(valSum);
var elMyElement = document.getElementById('<
alert(elMyElement); //returns nothing
document.getElementById("l
alert(document.getElementB
//elMyElement.innerHTML = valSum;
//document.getElementById(
}
How do you call or trigger function TotalUsedShares07() ? Can you show me the HTML code?
Also I don't imagine a 'label' by definition would have a 'value'. It would have text or HTML content, thus innerHTML is used to get or set its content. I have refactored your function this way:
function TotalUsedShares07() {
var value1 = document.getElementById('Number1').value,
value2 = document.getElementById('Number2').value,
value3 = document.getElementById('Number3').value,
theTotal = (parseFloat(value1) + parseFloat(value2) + parseFloat(value3));
document.getElementById('ResultTotal').innerHTML = theTotal;
}
and tested with this code, and it works fine...<div class="row">
<input type="number" id="Number1" name="Number1">
<input type="number" id="Number2" name="Number2">
<input type="number" id="Number3" name="Number3">
<label id="ResultTotal"></label>
</div>
<div class="row">
<input type="button" value="Set" onClick="TotalUsedShares07()">
</div>
ASKER
yes - so on any of the textboxes used i do the following:
<asp:TextBox ID="txtbx07d" runat="server" Width="50" onchange="TotalUsedShares0 7()"></asp :TextBox>
<asp:TextBox ID="txtbx07d" runat="server" Width="50" onchange="TotalUsedShares0
ASKER
my error when i try:
function TotalUsedShares07()
{
var _txtBox1 = document.getElementById('< %= txtbx07d.ClientID %>').value;
var _txtBox2 = document.getElementById('< %= txtbx07e.ClientID %>').value;
var _txtBox3 = document.getElementById('< %= txtbx07f.ClientID %>').value;
var value1 = _txtBox1;
var value2 = _txtBox2;
var value3 = _txtBox3;
var valSum = parseFloat(value1) + parseFloat(value2) + parseFloat(value3)
theTotal = valSum;
alert(theTotal);
document.getElementById('l bl07g').in nerHTML = theTotal;
}
Microsoft JScript runtime error: Unable to set value of the property 'innerHTML': object is null or undefined
function TotalUsedShares07()
{
var _txtBox1 = document.getElementById('<
var _txtBox2 = document.getElementById('<
var _txtBox3 = document.getElementById('<
var value1 = _txtBox1;
var value2 = _txtBox2;
var value3 = _txtBox3;
var valSum = parseFloat(value1) + parseFloat(value2) + parseFloat(value3)
theTotal = valSum;
alert(theTotal);
document.getElementById('l
}
Microsoft JScript runtime error: Unable to set value of the property 'innerHTML': object is null or undefined
ASKER
<asp:Label ID="lbl07g" runat="server" ></asp:Label> is how the label is set up
I think your IDs of your Textboxes might be the problem. Particularly the .ClientID portion. Double check those.
Hi,
ASP:Label will be rendered as SPAN tag in the web browser! So you have to use innerHTML for sure!
More over, ClientID is required!
onchange event will be fired, when you tab out of the text box, not when you edit the text! instead you can try onkeydown or onkeypress events!
Hope it helps u...
ASP:Label will be rendered as SPAN tag in the web browser! So you have to use innerHTML for sure!
More over, ClientID is required!
document.getElementById("<%=lbl07g.ClientID%>").innerHTML = theTotal;
onchange event will be fired, when you tab out of the text box, not when you edit the text! instead you can try onkeydown or onkeypress events!
Hope it helps u...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I would also set the ClientIDMode of the Label to Static.
<asp:Label ID="lblo7g" runat="server" ClientIDMode="Static"></as p:Label>
This way you dont have to use ClientID in javascript:
var label = document.getElementById("l bl07g");
You can also do this for the textboxes of course.
<asp:Label ID="lblo7g" runat="server" ClientIDMode="Static"></as
This way you dont have to use ClientID in javascript:
var label = document.getElementById("l
You can also do this for the textboxes of course.
Open in new window