Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    why won't this work :(

    1)

    Code:
    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:
    Code:
    <input type="button" value="Validate" onclick="Validate(survey);" />
    2)

    Code:
    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+'.')
    }
    Code:
    <input type="button" value="Click here to Purchase Web Statistics Reports" onClick="Purchase(reports);" />
    3)

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

  • #2
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    somebody help a newb? =[

  • #3
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    can you post the entire source code please, it'll make it easier to debug if there is anything wrong.
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #4
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by brandonH View Post
    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

    Code:
    <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>

  • #5
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    Code:
    <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

  • #6
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    okay I got everything else working now except this one little thing, I forget how to do math type stuff ;x

    Code:
    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+'.')
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •