PDA

View Full Version : Need Help With My Script



tarun
03-10-2007, 04:27 PM
Hi everyone,
I am tarun, and i am very new to javascript coding. Recently i have been working on this one code that wuould convret and tell you what you wud weigh on othe planets when the visiotor gives you his weight in an input box. so far i have this much and it doesnt seem to work, i think i know there is sumthing wrong with the onClick button,,but anywyas can any one please tell me whats wrong with it. Here is the code


<html>
<head>
<title> Find your weight on other planets </title>

<script>

function candy (form.ans.value)
{
a=eval(form.w.value)
b=(10*a*1.66)/10
form.moon.value=b
}

</script>


</head>


<body>

<form name=form>

<table>
<tr>
<td> Enter your weight here: <input type=text value="" name=w> </td>
</tr>
<tr>
<td> Click here to see what you weigh on other planets: <input type=button value="Click for your results" onClick="ans(this.form)"> </td>
</tr>
<tr>
<td> Click here to reset: <input type=reset value="Reset"><p> </td>
</tr>
<tr>
<td> Moon: <input type=text value="" name=moon> </td>
</tr>

</table>

</form>

</body>
</html>


any help would be greatly appreciated!!!

thetestingsite
03-10-2007, 05:09 PM
Change this:



onClick="ans(this.form)"


to this:



onClick="candy(this.form)"


Then in your code (between the head tags), make the following changes in red:



<script>

function candy(theForm)
{

a= theForm.w.value
b=(10*a*1.66)/10
theForm.moon.value=b
}

</script>


That should work for you. Hope this helps.

jscheuer1
03-10-2007, 05:13 PM
You cannot have the . character as a parameter for a function as you have done it. Try:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title> Find your weight on other planets </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function ans (form)
{
a=form.w.value
b=(10*a*1.66)/10
form.moon.value=b;
}
</script>
</head>
<body>
<form action="#">
<table>
<tr>
<td> Enter your weight here: <input type="text" value="" name="w"> </td>
</tr>
<tr>
<td> Click here to see what you weigh on other planets: <input type="button" value="Click for your results" onclick="ans(this.form)"> </td>
</tr>
<tr>
<td> Click here to reset: <input type="reset" value="Reset"><p> </td>
</tr>
<tr>
<td> Moon: <input type="text" value="" name="moon"> </td>
</tr>
</table>
</form>
</body>
</html>

jscheuer1
03-10-2007, 05:57 PM
BTW, your math is wrong for converting to 1/6 g's, it should be:


b=a*.66;