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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP!!!! the Very Simple program

Status
Not open for further replies.

kanat

Programmer
Joined
Oct 9, 2002
Messages
7
Location
KG
in the following code I get error, help please. I cant make it:


<SCRIPT Language=&quot;JavaScipt&quot;>
var a1 = 1
var res=0
var tmp=0

function check(q, a)
{
if (q==1)
if (a==a1) {
res=tmp+1
tmp = res
}
return true
}
function ShowRes()
{
window.document.text1.T1.value = res
}
</SCRIPT>

<BODY>
<div align=&quot;center&quot;>
<center>
<p> </p>
<p> </p>
<table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse&quot; bordercolor=&quot;#111111&quot; width=&quot;889&quot; height=&quot;205&quot; id=&quot;AutoNumber1&quot;>
<tr>
<td width=&quot;82&quot; height=&quot;38&quot;>Question 1</td>
<td width=&quot;801&quot; height=&quot;38&quot;> </td>
</tr>
<tr>
<td width=&quot;82&quot; height=&quot;39&quot;><font size=&quot;1&quot;>
<INPUT id=&quot;QA1-1&quot; type=&quot;radio&quot; value=&quot;QA1&quot; name=&quot;Group1&quot; OnClick='check(1, 1)'> 1</font></td>
<td width=&quot;801&quot; height=&quot;39&quot;> </td>
</tr>
<tr>
<td width=&quot;82&quot; height=&quot;39&quot;><font size=&quot;1&quot;>
<INPUT id=&quot;QA1-2&quot; type=&quot;radio&quot; value=&quot;QA1&quot; name=&quot;Group1&quot; OnClick='check(1, 2)'> 2</font></td>
<td width=&quot;801&quot; height=&quot;39&quot;> </td>
</tr>
<tr>
<td width=&quot;82&quot; height=&quot;39&quot;><font size=&quot;1&quot;>
<INPUT id=&quot;QA1-3&quot; type=&quot;radio&quot; value=&quot;QA1&quot; name=&quot;Group1&quot; OnClick='check(1,3)'> 3</font></td>
<td width=&quot;801&quot; height=&quot;39&quot;> </td>
</tr>
<tr>
<td width=&quot;82&quot; height=&quot;41&quot;><font size=&quot;1&quot;>
<INPUT id=&quot;QA1-4&quot; type=&quot;radio&quot; value=&quot;QA1&quot; name=&quot;Group1&quot; OnClick='check(1,4)'> 4</font></td>
<td width=&quot;801&quot; height=&quot;41&quot;> </td>
</tr>
</table>
</center>
</div>
 
A couple of problems from what you've posted:

a) You never seem to call [tt]ShowRes()[/tt] so the code will never display the results.

b) If you did call [tt]ShowRes()[/tt], you don't have a field called [tt]text1[/tt] in which to display the result.

c) Even if you did have a field called [tt]text1[/tt] in which to display the result, the [tt]ShowRes()[/tt] function attempts to set the value of the [tt]T1[/tt] attribute of the [tt]text1[/tt] field. Last time I checked, text fields don't have a [tt]T1[/tt] attribute. The body of the [tt]ShowRes()[/tt] function would need to be simply [tt]window.document.text1.value = res;[/tt].

And a few general pointers:
- In Javascript, even though some browsers will let you get away with not doing it, it is standard practise to terminate a line of code with a semicolon (;)

- When comparing two variables which contain numeric data it is wise to wrap either [tt]parseInt()[/tt] or [tt]parseFloat()[/tt] around the variables to ensure it is the numeric value of what the variable holds that you are comparing... otherwise you run the risk of comparing '22' to '3' and finding that the browser believes 22 < 3 = true.
 
thankx for your reply
this was a part of full code, that is why the T1 edit box does not appear in the text.

I fuond the mistake:
instead of &quot;Javascript&quot; there was &quot;JavaScipt&quot;, that is, 'r' letter was missing.
I write programs in VC++, and used to debuggers, that is why I could not find that mistake initially.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top