Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object expected error driving me nuts 1

Status
Not open for further replies.

jbtilley

Technical User
May 31, 2003
3
0
0
US
I have been getting an object expected error for a while now and I don't know why. Here is a simplified version of my code:

<body>
<form name=&quot;show&quot; method=&quot;post&quot; action=&quot;&quot;>
<input name=&quot;11&quot; type=&quot;text&quot; id=&quot;11&quot; value=&quot;0&quot; onChange=&quot;doMath();&quot;><br>
<input name=&quot;21&quot; type=&quot;text&quot; id=&quot;21&quot; value=&quot;0&quot; onChange=&quot;doMath();&quot;><br>
<input name=&quot;31&quot; type=&quot;text&quot; id=&quot;31&quot; value=&quot;0&quot;><br>
</form>
<script language=&quot;JavaScript&quot;>
<!--
function doMath() {

document.show.31.value= document.show.11.value + document.show.21.value;

}
//-->
</script>
</body>

I have tried parseInt just in case the text input needed to be changed to an int to get the same results. In the long run I want to limit users to entering an int from 0 to 20 and then have one read-only text input that displays the totals. Any advice/help?
 
Ok, OK I see it now. I can't give the text input fields in a form a name or id that starts with a number.

I just read that you can't use a number as a member of an object.

Putting an 'a' in like so cleared up the problem:

<body>
<form name=&quot;show&quot; method=&quot;post&quot; action=&quot;&quot;>
<input name=&quot;a11&quot; type=&quot;text&quot; id=&quot;a11&quot; value=&quot;0&quot; onChange=&quot;calculateTotals();&quot;><br>
<input name=&quot;a21&quot; type=&quot;text&quot; id=&quot;a21&quot; value=&quot;0&quot; onChange=&quot;calculateTotals();&quot;><br>
<input name=&quot;a31&quot; type=&quot;text&quot; id=&quot;a31&quot; value=&quot;0&quot;><br>
</form>
<script language=&quot;JavaScript&quot;>
<!--
function calculateTotals() {


document.show.a31.value = (Number(document.show.a11.value) + Number(document.show.a21.value));

}
//-->
</script>
</body>

pa' q' sepan
 
Try something along the lines of...

function doMath()
{ document.getElementById(&quot;31&quot;).value = document.getElementById(&quot;11&quot;).value + document.getElementById(&quot;21&quot;).value;
}


Good Luck! [thumbsup2]
WindUp
 
I just read that you can't use a number as a member of an object.

I got the basic idea, it's those little trivia questions that get me!


Good Luck! [thumbsup2]
WindUp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top