Hello,
I have the following JavaScript code. The purpose of the code is to check the content of a search form to insure that special characters are not being submitted. If there is an attempt to submit special characters, a warning message appears and the script will not submit the form. If there are no special characters, the script will submit the form.
The only special character that is allow is a comma. The script works good except for one thing.
If you enter a phrase such as "test, this" the string in the browser will read "test,%20this".
The script is not properly URLencoding the comma.
Does anyone know how to make the string getting properly encoded for the comma and any other special character we may allow, in the future, within the form input?
Thanks for your time.
function validSearch()
{
// Check For a Valid Search
if(document.searchform.theadd.value==''){
alert("Invalid Entry")
return false;
}
if(document.searchform.theadd.value==' '){
alert("Invalid Entry")
return false;
}
if(document.searchform.theadd.value==' '){
alert("Invalid Entry")
return false;
}
{
var iChars = "!@#$%^&*()+=-[]\';/{}|\":<>?";
for (var i = 0; i < document.forms["searchform"].theadd.value.length; i++) {
if (iChars.indexOf(document.forms['searchform'].theadd.value.charAt(i)) != -1)
{
alert("Invalid Entry - Enter only letters and numbers. Special characters are not allowed.")
return false;
}
}
{
var iChars = "!@#$%^&*()+=-[]\';/{}|\":<>?";
for (var i = 0; i < document.forms["searchform"].location.value.length; i++) {
if (iChars.indexOf(document.forms['searchform'].location.value.charAt(i)) != -1)
{
alert("Invalid Entry - Enter only letters and numbers. Special characters are not allowed.")
return false;
}
}
}
// alert("Valid Search")
document.searchform.action ="/";
document.searchform.submit();
}
}
I have the following JavaScript code. The purpose of the code is to check the content of a search form to insure that special characters are not being submitted. If there is an attempt to submit special characters, a warning message appears and the script will not submit the form. If there are no special characters, the script will submit the form.
The only special character that is allow is a comma. The script works good except for one thing.
If you enter a phrase such as "test, this" the string in the browser will read "test,%20this".
The script is not properly URLencoding the comma.
Does anyone know how to make the string getting properly encoded for the comma and any other special character we may allow, in the future, within the form input?
Thanks for your time.
function validSearch()
{
// Check For a Valid Search
if(document.searchform.theadd.value==''){
alert("Invalid Entry")
return false;
}
if(document.searchform.theadd.value==' '){
alert("Invalid Entry")
return false;
}
if(document.searchform.theadd.value==' '){
alert("Invalid Entry")
return false;
}
{
var iChars = "!@#$%^&*()+=-[]\';/{}|\":<>?";
for (var i = 0; i < document.forms["searchform"].theadd.value.length; i++) {
if (iChars.indexOf(document.forms['searchform'].theadd.value.charAt(i)) != -1)
{
alert("Invalid Entry - Enter only letters and numbers. Special characters are not allowed.")
return false;
}
}
{
var iChars = "!@#$%^&*()+=-[]\';/{}|\":<>?";
for (var i = 0; i < document.forms["searchform"].location.value.length; i++) {
if (iChars.indexOf(document.forms['searchform'].location.value.charAt(i)) != -1)
{
alert("Invalid Entry - Enter only letters and numbers. Special characters are not allowed.")
return false;
}
}
}
// alert("Valid Search")
document.searchform.action ="/";
document.searchform.submit();
}
}