James Polanski

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromJames Polanski
ToMe
SubjectCode Problems
Date20 July 2003 06:32
I am trying to do a simple calculation in Javascript.  The following is the
code, and it is not working.  Can you offer any help?


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Transmitter O</title>
<script LANGUAGE="JavaScript">
function neterp(transmitter, antenna, erp, form) {
//need to multiply the Inverse Log of antenna * .1 to get ratio
ratio = (Math.log(antenna) / Math.log(10))*.1;
form.erp.value = ratio * transmitter;
}
</script>
</head>
<body>
<form>
<div align="center"><center><table width="489">
<tr>
<td align="right" width="263" valign="middle">Transmitter O/P =</td>
<td align="left" width="218" valign="middle"><input type="text" size="8" value
name="transmitter"> watts</td>
</tr>
<tr>
<td align="right" width="263" valign="middle">Antenna Gain (after line loss) = </td>
<td align="left" width="218" valign="middle"><input type="text" size="8" value
name="antenna"> dBd</td>
</tr>
<tr>
<td width="481" align="center" valign="middle" colspan="2"><input type="button"
value="Calculate ERP" onClick="neterp(this.form.erp);"></td>
</tr>
<tr>
<td width="481" align="center" valign="middle" colspan="2"><input type="text" name="erp"
size="9"> Watts</td>
</tr>
</table>
</center></div>
</form>
</body>
</html>
FromMe
ToJames Polanski
SubjectRe: Code Problems
Date21 July 2003 08:50
James,

Your button onclick handler only passes one variable to the function, but
your function expects four. Try

---
onclick="neterp(this.form.transmitter.value,this.form.antenna.value,'unused',this.form);"
---

or, even more easy, use

---
onclick="neterp(this.form);"

function neterp(form) {
ratio = (Math.log(form.antenna.value) / Math.log(10))*.1;
form.erp.value = ratio * form.transmitter.value;
}
---

or, even more easy again, use

---
onclick="this.form.erp.value=(Math.log(this.form.antenna.value)/Math.log(10))*0.1*this.form.transmitter.value;"
---


Hope this helps

Tarquin
FromJames Polanski
ToMe
SubjectRe: Code Problems
Date21 July 2003 23:18
Tarquin:

I appreciate your help enormously....just your few lines of code turned a
light bulb on in my head and enabled me to better understand the handler
process.

Much appreciated.

I'm a JavaScript beginner......and have completed the page I was working on.
If you like, you can view it at:
http://xxx.xxxxxxxxxxxx.xx/calculators.html 


James
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.