Click to See Complete Forum and Search --> : js is new to me... help
nickos
02-01-2003, 11:57 AM
i just started learning today and i only really need to do one thing.. please see below
my code looks like this
http://www.superwang.com/js.htm which works but i want it to be like this
http://www.superwang.com/js2.htm but have no idea how to do it, i read up on it and still cant figure out how to make it work
does anyone understand what im trying to do?
Vamsee Krishna
02-01-2003, 12:22 PM
Originally posted by nickos
i just started learning today and i only really need to do one thing.. please see below
my code looks like this
http://www.superwang.com/js.htm which works but i want it to be like this
http://www.superwang.com/js2.htm but have no idea how to do it, i read up on it and still cant figure out how to make it work
does anyone understand what im trying to do?
Hi nickos,
checked out both the scripts...the first one seems to b working fine...but you've to check whether the user entered an integer or not...you can convert string to int by using the function parseInt() and to float by parseFloat()...the second script i.e. js2.html takes the input through a form and posts it to another script ( CGI hopefully )...so, JS can't help u much there...hope I'm clear...
nickos
02-01-2003, 05:32 PM
i dont think you understand what i want.. js.htm works just fine, but its not how i want the layout of the program to be.. i would like it to look like js2.htm, right now js2.htm is a worthless page just there to show you how i woul dlike to progran to look, you enter your length and width in the boxes, click submit and it comes up with a total in the total box
Vamsee Krishna
02-02-2003, 08:46 AM
Originally posted by nickos
i dont think you understand what i want.. js.htm works just fine, but its not how i want the layout of the program to be.. i would like it to look like js2.htm, right now js2.htm is a worthless page just there to show you how i woul dlike to progran to look, you enter your length and width in the boxes, click submit and it comes up with a total in the total box
ok, then this should help...:)
----------------------------------------------------------------------
<body>
<script language=javascript>
var base = parseFloat(0.66);
var min = 75;
function calculate()
{
var length = document.forms[0].length.value;
var width = document.forms[0].width.value;
var answer = length*width*base;
if( answer < min )
{
alert("The cost is less than"+min+"");
document.forms[0].answer.value = min;
}
else
{
document.forms[0].answer.value = answer;
}
}
</script>
<form>
<table>
<tr>
<td>Lenght:<input type=text name=length></td>
<td>Width:<input type=text name=width></td>
</tr>
<tr>
<td>Answer:<input type=text name=answer></td>
</tr>
<tr>
<td colspan=3>
<input type=button value=Click onClick="calculate()">
</td>
</tr>
</table>
</form>
</body>
----------------------------------------------------------------------
Let me know if it helped you
bye
nickos
02-02-2003, 08:47 AM
i got it thanks :)