INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

URLencode and Submit a form

URLencode and Submit a form

(OP)
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();
}
}

RE: URLencode and Submit a form

Quote:

The script is not properly URLencoding the comma.

commas are allowed in URLs, so do not require encoding, spaces are not so are encoded.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close