Welcome to Dream.In.Code
Getting Help is Easy!

Join 86,261 Programmers. There are 1,898 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

return statement outside of fx

 
Reply to this topicStart new topic

return statement outside of fx

raeNet
post 26 Apr, 2008 - 12:49 PM
Post #1


D.I.C Head

**
Joined: 1 Nov, 2007
Posts: 70



I'm trying to validate the radio buttons in my form (all I need is to make sure a selection is made & if not inform the user), but I'm getting an error 'return' statement is outside of function.
Can anyone help me fix this problem. I've tried so many validations on radio buttons and I'm plain disgusted.

Thanks in advance

CODE

<html>
<head>
<title>Form</title>
<script type="text/javascript"> language="JavaScript">
<!-- <![CDATA[

   function getRadioValue(banquet,size)
    {
    var theRadioButtons = document.banquet.size;
    for (i=0;i<theRadioButtons.length;i++)
    {
      if (theRatioButtons[i].checked)
    {
       return theRadioButtons[i].value;
}
}
}
   function calculate()
    {
    with(document.banquet)
    {
    total.value = (meals.value*hiddenField.value)
    }
}
   function validate()
    {
    if(document.banquet.wName.value <2)
    {
       alert("wName's name is invalid. Please select name from list.");
       document.banquet.wName.focus();
       return false;
    }
    if(!document.banquet.text02.value)
    {
       alert("You must enter your name to properly submit form.");
       document.banquet.text02.focus();
       return false;
    }
    if(!document.banquet.text03.value)
    {
       alert("Please enter a proper email address.");
       document.banquet.text03.focus();
       return false;
    }
    if(!document.banquet.text04.value)
    {
       alert("Please enter your telephone number.");
       document.banquet.text04.focus();
       return false;
    }
    if(!document.banquet.meals.value)
    {
       alert("Please enter # Attending.");
       document.banquet.meals.focus();
       return false;
    }
}
    var chosenSize = getRadioValue("banquet","size");
    if (chosenSize==null)
    {
       alert("Please select T-shirt size");
       return false;
    
    }else{
    return true;
    }
}

// ] ]>-->
</script>
</head>
<body>
<p><b><font face="Arial" size="2"></p>
<a href="index.html">Home</a></b></font></li>

<form name="banquet" method="post" action="ThankYou.htm" onsubmit="return validate();">

<table width="70%" border="0" cellspacing="0" cellpadding="4">
<tr bgcolor="silver">
<td colspan="2">
<p align="center"><strong>Registration Form</strong></p>
<tr bgcolor="#6699cc">
<td>
<p align="right"><label for="wName">Name</label></p>
</td>
<td align="left">
<select name="wName" style="background:#f0f8ff">
<option value="1">Select Name</option>
<option value="2">NAME1</option>
<option value="3">NAME2</option>
<option value="4">NAME3</option>
<option value="5">NAME4</option>

</select>
</td>
</tr>
<tr>
<td>
<p align="right"><label for="submittedby">Form Completed by:</label></p>
</td>
<td align="left">
<input id="submittedby" type="text" name="text02" style="background:#f0f8ff" size="30">
</td>
</tr>
<tr>
<td>
<p align="right"><label for="email">E-mail:</label></p>
</td>
<td align="left">
<input id="email" type="text" name="text03" style="background:#f0f8ff"size="25">
</td>
</tr>
<tr>
<td>
<p align="right"><label for="phone">Telephone No.:</label></p>
</td>
<td align="left">
<input id="phone" type="text" name="text04" style="background:#f0f8ff"size="12">
</td>
</tr>
<tr bgcolor="#6699cc">
<td align="left">
<p align="right"><label for="attending">Total # Attending:</label> <br \>
</td>
<td align="left">
<input type="text" name="meals" style="background:#f0f8ff"size="5"</p>
<input type="button" name="Button" value="Calculate" onclick="calculate()"> @ $8.75 per person</>
</tr>
<tr bgcolor="#6699cc">
<td>
<p align="right"><label for="total">Please issue checks to Organization for: </label><br \>
<font size="-1">(Mail to: Name, Addr1, City, ST zip)</p>
</td>
<td align="left">
<p> $<input type="text" style="background:silver" name="total" value="Total" size="10"</p>
<br \>
<br \>
<input type="hidden" name="hiddenField" value="8.75">
</td>
</tr>

<tr>
<td>
<p align="right">Name's T-Shirt Size:</label> </p>
</td>
<td align="left">
<label for="r1"><input id="r1" type="radio" name="size" value="1"/>Small</label>
<label for="r2"><input id="r2" type="radio" name="size" value="2"/>Medium</label>
<label for="r3"><input id="r3" type="radio" name="size" value="3"/>Large</label>
</td>
</tr>

<tr bgcolor="#6699cc">
<td colspan="2">
<label for="comments">Please enter comments / suggestions for this year's banquet below:</label><br />
<textarea id="comments" name="commentstext" rows="5" cols="60" style="background:#f0f8ff"></textarea>

</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" style="background:navy" style="color:silver" value="Submit form"/>
<input type="reset" style="background:navy" style="color:silver" value="Reset fields"/>
</td>
</tr>

</table>

</form>
</div>
</body>
</html>


This post has been edited by raeNet: 26 Apr, 2008 - 12:50 PM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


pertheusual
post 26 Apr, 2008 - 01:54 PM
Post #2


D.I.C Head

**
Joined: 26 Jan, 2008
Posts: 212

That's because your return statement is outside the function tongue.gif

You have an extra curly bracket.
jscript

var chosenSize = getRadioValue("banquet","size");

The curly bracket before this line ends the function.
So the return statements here
jscript

if (chosenSize==null)
{
alert("Please select T-shirt size");
return false;

}else{
return true;
}

are outside the validate function.

You should really a syntax highlighting text editor or something. They really help avoid errors like this.

Per
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

raeNet
post 26 Apr, 2008 - 02:06 PM
Post #3


D.I.C Head

**
Joined: 1 Nov, 2007
Posts: 70

Hi Per - thx for the quick response.

Now my Error reads: theRadioButtons is undefined. What's that about?
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

pertheusual
post 26 Apr, 2008 - 02:45 PM
Post #4


D.I.C Head

**
Joined: 26 Jan, 2008
Posts: 212

You misspelled "theRadioButtons"

jscript

for (i=0;i<theRadioButtons.length;i++)
{
if (theRatioButtons[i].checked) //HERE
{
return theRadioButtons[i].value;
}
}


You wrote "Ratio" with a "t". tongue.gif

Also, in the code you posted, there was an extra ">" in the <script> tag.

Per
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

raeNet
post 26 Apr, 2008 - 02:54 PM
Post #5


D.I.C Head

**
Joined: 1 Nov, 2007
Posts: 70

Wow - double thank you!!

I looked at this so many times, but I was more worried about syntax than typos.

Again, thanks for helping me out on this!!!!!!!
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

pertheusual
post 26 Apr, 2008 - 09:41 PM
Post #6


D.I.C Head

**
Joined: 26 Jan, 2008
Posts: 212

No problem. Took me a minute too.

Per
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 5/16/08 10:19AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month