Can someone point me in the right direction, please?
I have a multi-page online form.
I save the contents of each page in a cookie, using Name/Value pairs
-- with the equal-sign ("=") and the semi-colon (";") as delimiters.
The above was working fine.
Then I discovered that if the user enters an equal-sign or a semi-colon in a text box or textarea field, my Name/Value pairs no longer work.
So I tried to write a function (stripDelim.
js) to be included in each page of the form, which would take the string that the user entered and strip from it any equal-sign or semi-colon characters it encountered, before returning it and adding it to the cookie string.
However, whether I say:
if ( charAt(strOld[i]) == charAt(strDelim[j]) )
or I say:
if ( strOld.charAt[i] == strDelim.charAt[j] )
I keep getting an error (in the 1st case) or the value "undefined" when I display these variables in an alert box (in the 2nd case). .
-------------------------------------------
Below is my function:
strDelim = ";="; // string containing cookie delimiters
function stripDelim(strOld){
/*
input = string entered by user ("strOld")
output = user string with delimiters stripped from it ("strNew")
if the character at strOld[i] is not a cookie delimiter, then add the character to strNew
when done, return strNew
*/
var strNew = "";
for (var i = 0; i < strOld.length; i++)
{
for (var j = 0; j < strDelim.length; j++)
{
// if ( charAt(strOld[i]) == charAt(strDelim[j]) )
if ( strOld.charAt[i] == strDelim.charAt[j] )
{
// do nothing
}
else
{
strNew += strOld.charAt[i];
}
alert ("strOld.charAt[i] = " + strOld.charAt[i] + " strDelim.charAt[j] = " + strDelim.charAt[j] + " strNew = " + strNew);
} // end inner for
} // end outer for
return strNew;
} // end function
-----------------------------------
Below is how I included the function in the 1st page of my form (N.B., if it matters, I also had another script in the Head, specific to Page 1):
<head>
<title>Multipage Application Form - Page 1</title>
<script type="text/javascript" src="stripDelim.
js">
</script>
<script language="JavaScript">
var strForm1 = ""; // global variable
function gotoNext(){
// blah, blah, blah
} // end function gotoNext()
</head>
---------------------------------------
Below is how I called stripDelim() in my function gotoNext() for Page 1:
var strCookie = "StartForm1;";
for (var i = 0; i < frmPage1.elements.length - 1; i++)
{
if (frmPage1.elements[i].type == "text" || frmPage1.elements[i].type == "textarea")
{
strCookie += stripDelim(frmPage1.elements[i].value) + ";";
}
else
{
strCookie += frmPage1.elements[i].value + ";";
}
} // end IF
} // end For-Loop