Form Validation -- Passing White Space in JavaScript Descriptor
Hi, I am trying to adapt the form validation script at http://www.javascript-coder.com/html...lidation.phtml to a site that already has tons of pages with forms. Unfortunately, the forms include selection lists that often have SELECT names with white spaces included, and these do not work when passed as a variable to the frmvalidator function
This works:
frmvalidator.addValidation("Country","dontselect=0");
This does not work:
frmvalidator.addValidation("My Country","dontselect=0");
The site I want to use the script on is being database generated and has something like 25,000 item pages, each with several SELECT list options. The Option variable uploaded to the database looks like:
Code:
"Optional Out Going Mail Slot" "Please Choose" "None, Thanks" "Please Add Mailslot in Top Left (Item # na) (+$15.00)" "Please Add Mailslot in Top Right (Item # na) (+$15.00)" "Please Add Mailslot in Bottom Left (Item # na) (+$15.00)" "Please Add Mailslot in Bottom Right (Item # na) (+$15.00)"
so it would be a serious task to download the database, loop through and replace white-space characters with dashes or underscores on the first element in each option sequence. Is there some way to make names with white spaces work? I could switch to a script that simply checks all selection lists to make sure that option 0 is not selected. But I love all the other features of name, format and combined verification in the above script. Unfortunately, the script relies on the name and validation action of each form element being passed to its function onSubmit. I thought I would ask if anyone can see a way to adapt the script to handling white-spaces before giving up on the idea.
Question is, are there ways to fix this problem short of reworking the entire database to eliminate white-spaces? If I must rework the database, can I use the ASCII or Unicode non-breaking-space or must I substitute an underscore or dash character for each white-space?
EDIT: Further to that, I set up a test using the Unicode non-breaking-space. It displays fine in HTML, but JavaScript chokes on it. Doesn't work.
Maybe I have been over thinking this. I could use the query language in the site's back end to strip out the white-spaces in the SELECT list name. So instead of "Optional Out Going Mail Slot", which I display as the LABEL for the SELECT list, I write the name as "OptionalOutGoingMailSlot" and pass that to my script. The only downside is some of the error messages my script throws will get a bit strange looking, like
OptionalOutGoingMailSlot: Please select one option.
So, now the question becomes can I use JS to loop through the output string and insert a space before each Capital Letter in the name?
Interesting. I tested it server side, and it failed, but it works on the desktop. Not robust enough. I think I need to use underscores to be certain it works. That still yields a perfectly readable error output.
One complicating factor is that on the Yahoo Store platform, there is a security setting that causes the cart to reject any unrecognized options. I can turn it off, but if I do, hackers can pass price modifiers to the cart in the query string and they will be accepted. So I am best off leaving the Reject unrecognized options flag sat, and making the SELECT list names work in JavaScript, human reader's eyes, and the cart.
The Unicode is only in the script , not in the html
Outstanding. Based on your confidence, I went back and tested it again on the Yahoo Store server. Indeed it does woik with the Unicode non-breaking-space. See http://www.babygiftsandproducts.com/form-test.htm for a test of the script.
Thanks, Fang. I can write an RTML routine to find the white spaces in the name element of each SELECT list and replace them with the Unicode non-breaking-space character. RTML supports Perl REGEX search and replace. So I can use it to loop through the database, update each Option SELECT list, and export a CSV file which I can then use to actually modify the database.
Problem solved.
EDIT: Drat. Spoke too soon. JavaScript handles the Unicode non-breaking-space but Yahoo's back end doesn't. Using it in an option name causes the item to refuse to submit to the cart. I guess it's either underscores or CamelCase.
Bookmarks