Click to See Complete Forum and Search --> : special characters. HELP!!!
Here is the page http://www.zone.ee/crae/createeps.php
Open the site and you will see an input boxes where you have to type something.
I want you to make a Javascript that if somebody types characters [(,<>/\";|{})] in YOUR NAME, YOUR E-MAIL or in EPISODE's TITLE input box, then after pressing Submit button, an error-message-box appears and says that you can't type such characters for YOUR NAME, YOUR EMAIL and EPISODE's TITLE fields. But it's alright when you type such caracters in the last field ("Write/paste your episode here")
COULD YOU now make that Javascript and set it up on the file? And then paste the file contents here.
And for that, I could put your name somewhere on that site.
Thanks,
Hurry!
And by the way, I didn't find such Javascript anywhere. So it is up to you to make it.
And I forgot to say that there is one more special character that you can't type in the fields, it is *
Then I could advertise your name on the site.
Like: Special thanks to *yourname*
thank you
Charles
02-24-2003, 10:39 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Form Example</title>
<form action="someScript.pl" onsubmit="return false">
<script type="text/javascript">
<!--
function badChars (field) {if (/[\[(,<>\/\\";|{})\]\*]/g.test(field.value)) {
alert ('This field cannot contain the following characters: [(,<>/\";|{})]*');
field.value='';
field.focus();
}};
// -->
</script>
<p><label for="name">Your Name</label><br><input id="name" type="text" onchange="badChars(this)"></p>
<p><label for="email">Your Email</label><br><input id="email" type="text" onchange="badChars(this)"></p>
<p><label for="title">Title</label><br><input id="title" type="text" onchange="badChars(this)"></p>
<p><textarea rows="10" cols="50"></textarea></p>
<p><input type="submit" value="Submit Episode"> <input type="reset" value="Reset Form"></p>
</form>
Thanks, but give me a moment to test this script...
You did a great job. Thanks. I will put your name on the Contact page.
Like Javascripts by Charles.
Should I put also your email address?
Everything works fine, but I would prefer if the message box appears AFTER I HAVE PRESSED the SUBMIT button. But now, it appears right when you go to another field.
How to do that the Error Box appears when clicking the Submit Button?
I had written this, and then saw that Charles had already posted. But, this code will wait until you hit submit to validate:
This code goes in you <head>
function validate()
{
var invalidChars = "[(,<>/\\\"*;|{})]"; // Invalid characters
var x = 0;
var s = document.submitform;
for (i=0; i<invalidChars.length; i++)
{
badChar = invalidChars.charAt(i)
if (s.yourname.value.indexOf(badChar,0) > -1)
{
x=1;
}
if (s.email.value.indexOf(badChar,0) > -1)
{
x=1;
}
if (s.title.value.indexOf(badChar,0) > -1)
{
x=1;
}
}
if (x == 1)
{
alert ("Name, Email, and Episode Title can not contain the following characters:\n\n[ ( , < > / \\ \" * ; | { } ) ]");
return false;
}
return true;
}
</script>
and this is your <form> tag...
<form name="submitform" onsubmit="return validate()" method="post" action="thankeps.php">
Charles
02-24-2003, 11:59 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Form Example</title>
<form action="someScript.pl" onsubmit="return validate(this)">
<script type="text/javascript">
<!--
function validate (f) {
var valid = true;
if (/[^\s\w\d]/.test(f.name.value)) {alert('Field "Your Name" contains one or more illegal characters.'); f.name.value = ''; valid = false};
if (!/^[\w\d]+@[\w\d]+\.[\w\d]+$/.test(f.email.value)) {alert('Field "Your Email" appears to contain an illegal email address.'); f.email.value = ''; valid = false};
if (/[^\s\w\d]/.test(f.title.value)) {alert('Field "Title" contains one or more illegal characters.'); f.title.value = ''; valid = false};
return valid;
};
// -->
</script>
<p><label for="name">Your Name</label><br><input id="name" name="name" type="text"></p>
<p><label for="email">Your Email</label><br><input id="email" name="email" type="text"></p>
<p><label for="title">Title</label><br><input id="title" name="title" type="text"></p>
<p><label for="episode">Episode</label><br><textarea rows="10" cols="50" id="episode"></textarea></p>
<p><input type="submit" value="Submit Episode"> <input type="reset" value="Reset Form"></p>
</form>
I would prefer that you not attribute anything to me, but if you wish to express your thanks, then please conform your page to the Web Content Accessibility Guidelines 1.0 Lever Double A (http://www.w3.org/TR/WCAG10/).
Cool. Everything is perfect. I don't know which one I will take, but thanks both of you!
I will test them now.
I put your names on the site (http://www.hot.ee/mortalconquest/contact.htm)
I put your link too, Charles.
If someone wants, I can put your email addresses too. Just let me know.
Thanks again!!!!!
:cool: