Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 21st, 2005, 12:50 PM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default statement outside of function

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript">
var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
for (i=o; i<invalidChars.length; i++)
{
if (testField.indexOf(invalidChars.charAt(i),0) > -1)
{return false;}
}
</script>
</head>

<body>
<form onSubmit="return invalidChars();">
<input type="text" name="testField">
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

Whats wrong with my code???

I get:

Error:

'return' statement outside of function

www.crmpicco.co.uk
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
Reply With Quote
  #2 (permalink)  
Old February 21st, 2005, 12:54 PM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
for (i=o; i<invalidChars.length; i++)
{
if (agency.indexOf(invalidChars.charAt(i),0) > -1)
{return false;}
}

Its the Javascript thats giving me an error

Why?

www.crmpicco.co.uk
Reply With Quote
  #3 (permalink)  
Old February 21st, 2005, 01:07 PM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

I've now got this but still get error:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="javascript">
function removeBadCharacters(text)
{
   if (text.replace) {
      text.replace(/[<>\"\'%;\)\(&\+]/, '');
   }
   return string;
}


</script>

</head>

<body>
<form name="form">
<input type="text" name="text">
<input type="submit" name="submit" onClick="return removeBadCharacters();">
</form>
</body>
</html>


www.crmpicco.co.uk
Reply With Quote
  #4 (permalink)  
Old February 21st, 2005, 01:29 PM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

http://javascript.internet.com/forms/val-char.html

www.crmpicco.co.uk
Reply With Quote
  #5 (permalink)  
Old February 22nd, 2005, 01:08 AM
Friend of Wrox
 
Join Date: Dec 2004
Location: Chennai, Tamil nadu, India.
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

What is your actual problem? By the way do you face that "problem" still?

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
Reply With Quote
  #6 (permalink)  
Old February 22nd, 2005, 04:28 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Your first problem was exactly what the error message said, you can't return a value from a function if you are not in a function, where would it return it to?
I don't know what erreor message you are getting in the latest version but "string" is not defined in the code shown. You may want:
Code:
function removeBadCharacters(text) 
{
   if (text.replace) {
      return text.replace(/[<>\"\'%;\)\(&\+]/g, '');
   }
}

--

Joe (Microsoft MVP - XML)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help writing SQL Statement/ .net code for function carswelljr Classic ASP Databases 2 August 24th, 2006 03:31 PM
if statement and contains function richjo100 XSLT 6 September 27th, 2004 05:04 AM
retreive function/Line from macro or function? MikoMax J2EE 0 April 1st, 2004 04:42 AM
Calling a Function within an MS SQL Statement flyin Classic ASP Databases 3 September 5th, 2003 03:10 AM



All times are GMT -4. The time now is 10:00 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.