...

View Full Version : why won't this work :(



tazdingo
12-05-2006, 12:56 AM
1)



function Validate(survey)
{
if(IsEmpty(survey.last_name))
{
alert('You have not entered a last name!')
survey.last_name.focus();
return false;
}
return true;
}


and where I use it:

<input type="button" value="Validate" onclick="Validate(survey);" />

2)



function Purchase()
{
var answer = prompt("How many reports do you wish to purchase, at $8 each?")
answer2 = (answer*8)+(answer*0.06)
alert('The total price for your purchase is '+answer2+'.')
}



<input type="button" value="Click here to Purchase Web Statistics Reports" onClick="Purchase(reports);" />

3)



if (survey.pwd.value.length < 5)
{
alert ("Please enter a password of at least 5 characters!");
survey.pwd.focus();
return false;
}

tazdingo
12-05-2006, 04:01 AM
somebody help a newb? =[

brandonH
12-05-2006, 04:40 AM
can you post the entire source code please, it'll make it easier to debug if there is anything wrong.

tazdingo
12-05-2006, 08:10 PM
can you post the entire source code please, it'll make it easier to debug if there is anything wrong.
I did that because they said not to post the whole thing, but okay :p



<HTML>
<HEAD><TITLE>blah</TITLE>
<script language="Javascript">
function Validate(survey)
{
if(IsEmpty(survey.last_name))
{
alert('You have not entered a last name!')
survey.last_name.focus();
return false;
}
return true;
}
function Purchase()
{
var answer = prompt("How many reports do you wish to purchase, at $8 each?")
answer2 = (answer*8)+(answer*0.06)
alert('The total price for your purchase is '+answer2+'.')
}
if (survey.pwd.value.length < 5)
{
alert ("Please enter a password of at least 5 characters!");
survey.pwd.focus();
return false;
}
</script>
</head>
<BODY>
<H1 align=center>Web Weekly Survey - Your Opinion Counts</H1>
<P>Please take this survey. Your answers will help us to improve Web Weekly.</P>
<HR>

<FORM id="survey" name="survey">
<TABLE>
<TR>
<TD width=150><LABEL for="first_name">First name:</LABEL> </TD>
<TD><INPUT id="first_name" name="first_name"> </TD>
<TD width=150><LABEL for="mid_init">Middle initial:</LABEL> </TD>
<TD><INPUT id="mid_init" name="mid_init" size="1"></TD>
</tr><tr>
<TD width=150><LABEL for="last_name">Last name:</LABEL> </TD>
<TD><INPUT id="last_name" name="last_name"></TD>
</TR><tr>
<td width=150><label for="pwd">Password:</label></td>
<td><input id="pwd" name="pwd" size="5"></td>
</tr><tr>
<td width=150><label for="length">Length of Time Customer Has Been Receiving Web Weekly:</label></td>
<td>
<input type="radio" name="lessone" id="lessone">
<label for="lessone">Less than 1 year</label><br>
<input type="radio" name="onetofive" id="onetofive">
<label for="onetofive">More than 1 year but less than 5 years</label><br>
<input type="radio" name="morefive" id="morefive">
<label for="morefive">More than 5 years</label>
</td>
</tr><tr>
<td width=150><label for="ways">Ways in Which Customer Heard About Web Weekly:</label></td>
<td>
<input type="checkbox" name="friend" id="friend">
<label for="friend">From a friend</label><br>
<input type="checkbox" name="boss" id="boss">
<label for="boss">From a boss</label><br>
<input type="checkbox" name="ad" id="ad">
<label for="ad">From Ad in Magazine</label><br>
<input type="checkbox" name="link" id="link">
<label for="link">From Internet Link</label>
</td>
</tr><tr>
<td width=150><label for="bestarea">Area of Web Weekly Customer Likes Best:</label></td>
<td>
<select name="bestarea" id="bestarea">
<option>Market Place</option>
<option>What's Happening</option>
<option>Companies on the Move</option>
<option>Tutorials, Editorials</option>
</select>
</td>
</tr><tr>
<td width=150><label for="comments">Comments:</label></td>
<td><textarea rows="5"></textarea></td>
</tr><tr>
<td>
<input type="button" value="Validate" onclick="Validate(survey);" />
<input type="reset" value="Reset" />
<input type="submit" value="Submit" />
</td>
</tr>
</TABLE>
</FORM>
<input type="button" value="Click here to Purchase Web Statistics Reports"
onClick="Purchase(reports);" />
<marquee align="center">Tell your friends about Web Weekly!</marquee>
</BODY>
</HTML>

david_kw
12-05-2006, 09:09 PM
Two problems I found:

1) The function IsEmpty() isn't defined. So try:

if(survey.last_name.value=="")

2) The password validation check isn't in a function. So move:

if (survey.pwd.value.length < 5)
{
alert ("Please enter a password of at least 5 characters!");
survey.pwd.focus();
return false;
}

Inside Validate()

There might be other problems but fixing these two got the Validate button working and hopefully get you pointed in the right direction.



<HTML>
<HEAD><TITLE>blah</TITLE>
<script language="Javascript">
function Validate(survey)
{
if(survey.last_name.value=="")
{
alert('You have not entered a last name!')
survey.last_name.focus();
return false;
}
if (survey.pwd.value.length < 5)
{
alert ("Please enter a password of at least 5 characters!");
survey.pwd.focus();
return false;
}
return true;
}
function Purchase()
{
var answer = prompt("How many reports do you wish to purchase, at $8 each?")
answer2 = (answer*8)+(answer*0.06)
alert('The total price for your purchase is '+answer2+'.')
}
</script>
</head>
<BODY>
<H1 align=center>Web Weekly Survey - Your Opinion Counts</H1>
<P>Please take this survey. Your answers will help us to improve Web Weekly.</P>
<HR>

<FORM id="survey" name="survey">
<TABLE>
<TR>

<TD width=150><LABEL for="first_name">First name:</LABEL> </TD>
<TD><INPUT id="first_name" name="first_name"> </TD>
<TD width=150><LABEL for="mid_init">Middle initial:</LABEL> </TD>
<TD><INPUT id="mid_init" name="mid_init" size="1"></TD>
</tr><tr>
<TD width=150><LABEL for="last_name">Last name:</LABEL> </TD>

<TD><INPUT id="last_name" name="last_name"></TD>
</TR><tr>
<td width=150><label for="pwd">Password:</label></td>
<td><input id="pwd" name="pwd" size="5"></td>
</tr><tr>
<td width=150><label for="length">Length of Time Customer Has Been Receiving Web Weekly:</label></td>
<td>
<input type="radio" name="lessone" id="lessone">

<label for="lessone">Less than 1 year</label><br>
<input type="radio" name="onetofive" id="onetofive">
<label for="onetofive">More than 1 year but less than 5 years</label><br>
<input type="radio" name="morefive" id="morefive">
<label for="morefive">More than 5 years</label>
</td>
</tr><tr>

<td width=150><label for="ways">Ways in Which Customer Heard About Web Weekly:</label></td>
<td>
<input type="checkbox" name="friend" id="friend">
<label for="friend">From a friend</label><br>
<input type="checkbox" name="boss" id="boss">
<label for="boss">From a boss</label><br>
<input type="checkbox" name="ad" id="ad">

<label for="ad">From Ad in Magazine</label><br>
<input type="checkbox" name="link" id="link">
<label for="link">From Internet Link</label>
</td>
</tr><tr>
<td width=150><label for="bestarea">Area of Web Weekly Customer Likes Best:</label></td>
<td>

<select name="bestarea" id="bestarea">
<option>Market Place</option>
<option>What's Happening</option>
<option>Companies on the Move</option>
<option>Tutorials, Editorials</option>
</select>
</td>

</tr><tr>
<td width=150><label for="comments">Comments:</label></td>
<td><textarea rows="5"></textarea></td>
</tr><tr>
<td>
<input type="button" value="Validate" onclick="Validate(survey);" />
<input type="reset" value="Reset" />
<input type="submit" value="Submit" />

</td>
</tr>
</TABLE>
</FORM>
<input type="button" value="Click here to Purchase Web Statistics Reports"
onClick="Purchase(reports);" />
<marquee align="center">Tell your friends about Web Weekly!</marquee>
</BODY>
</HTML>


david_kw

tazdingo
12-05-2006, 10:07 PM
okay I got everything else working now except this one little thing, I forget how to do math type stuff ;x



function purchase()
{
var answer = prompt("How many reports do you wish to purchase, at $8 each?","")
var cost = (answer*8)
var tax = (answer*0.06)
var answer2 = (cost+tax)
alert('The total price for your purchase is '+answer2+'.')
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum