PDA

View Full Version : JavaScript problem :(


Firegurl
11-06-2002, 09:32 PM
I'm trying to make this javascript thing that will show a different picture depending on the amount put into the box. At the moment i have got it to read it etc,, but the picture only is there for about 1/2 second. I want it to stay there. Can anyone find what is wrong?

Click here to see the page (http://www21.brinkster.com/oatley/java/afford.html)


here is my script <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>What can i afford?</title>

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin script
function conVerter(myform) {
var money=document.test.savings.value
if (money >=200) {document.Box.src = "image3.gif";}
else {if (money >=50) {document.Box.src = "image1.gif";}
else {if (money <=50) {document.Box.src = "image2.gif";}
}
}
}
//-->
</Script>

</head>

<body bgcolor="#003366" text="#FFFFFF">




<table width="100%" height="268" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2"><div align="center"><img src="banner.gif" width="206" height="131"></div></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><div align="center">Enter Your Savings Value</div></td>
<td><form name="test">
<div align="left">
<input type="text" name="savings">
</div>
<div align="left"><BR>
</div>
<tr>
<td colspan="2">
<div align="center">
<input type="submit" value="Tell Me What I Can Afford" onClick="conVerter()">
</div>
</table>
</form>
<P>
<CENTER>
<img src="spacer.gif" name="Box" width="206" height="131">
</CENTER>
<P>

</body>
</html>

Inch
11-07-2002, 07:18 AM
Firegurl,
Your script won't work becuase as soon as you post the contents of the form, the value of the savings field within your form resets - hence the picture doesn't show.

Change:
<input type="submit" value="Tell Me What I Can Afford" onClick="conVerter()">

into:
<input type="button" value="Tell Me What I Can Afford" onClick="conVerter()">

This works fine, as it doesn't submit your form, just calls the function.

hope that helps... :)