Posts: 1
|
I added a javascript that on click takes the form info and "posts" it to two different server side asp scripts.... One for email and one for mailing list ...
That works fine... But my form validation script no longer works properly..at best it checks the first line but info gets submitted anyways....
I have tried multiple javascript on submit scripts none seems to work... here is the code...any help appreciated.... cause I'm all stumped...
<html><head><title>Mailing list Contact/mailing list</title>
</head><body>
<script type="text/javascript" language="JavaScript">
<!-- Copyright 2005 Bontrager Connection, LLC
//
// Two places need to be customized.
//
//
// Place 1:
// Between the quotation marks, specify the name of
// your form.
var FormName = "theForm";
// Place 2:
// Between the quotation marks, specify the field names
// that are required. List the field name separated
// with a comma.
var RequiredFields = "Firstname,email,Message";
//
// No other customization of this JavaScript is required.
//
/////////////////////////////////////////////////////////
function ValidateRequiredFields()
{
var FieldList = RequiredFields.split(",")
var BadList = new Array();
for(var i = 0; i < FieldList.length; i++) {
var s = eval('document.' + FormName + '.' + FieldList[i] + '.value');
s = StripSpacesFromEnds(s);
if(s.length < 1) { BadList.push(FieldList[i]); }
}
if(BadList.length < 1) { return true; }
var ess = new String();
if(BadList.length > 1) { ess = 's'; }
var message = new String('\n\nThe following field' + ess + ' are required:\n');
for(var i = 0; i < BadList.length; i++) { message += '\n' + BadList[i]; }
alert(message);
return false;
}
function StripSpacesFromEnds(s)
{
while((s.indexOf(' ',0) == 0) && (s.length> 1)) {
s = s.substring(1,s.length);
}
while((s.lastIndexOf(' ') == (s.length - 1)) && (s.length> 1)) {
s = s.substring(0,(s.length - 1));
}
if((s.indexOf(' ',0) == 0) && (s.length == 1)) { s = ''; }
return s;
}
// -->
</script>
<form
name="theForm"
onsubmit="return ValidateRequiredFields();"
method="POST" action="mailinglist/default.asp?add">
<table border="0" cellpadding="5" cellspacing="5" class="table" style="width:3in; background-color: #DFECEB;" >
<tr>
<td nowrap align="right">
<p class="label">Email Address</p> </td>
<td nowrap>
<input name="email" value="enter your email" onFocus="this.value='';" class="input" style="width:100%; background-color: #FFFFCC;" size="20" > </td>
</tr>
<tr>
<td nowrap valign="top" align="right">
<p class="label">First Name</p> </td>
<td nowrap>
<p align="left">
<input name="FirstName" style="width:100%; background-color: #FFFFCC;" value="" size="20"></td>
</tr>
<tr>
<td nowrap valign="top" align="right">
<p class="label">Last Name</td>
<td nowrap>
<p align="left">
<input name="LastName" value="" style="width:100%; background-color: #FFFFCC;" size="20">
</p> </td>
</tr>
<tr>
<td nowrap valign="top" align="right">
<p class="label">Phone Number</p> </td>
<td nowrap>
<p align="left">
<input name="Phone" style="width:100%" value="" size="20"></p></td>
</tr>
<tr>
<td nowrap valign="top" align="right">
<p class="label">Company</p> </td>
<td nowrap>
<p align="left">
<input name="Company" style="width:100%" value="" size="20"></p></td>
</tr>
<tr>
<td nowrap valign="top" align="right">
<p class="label">message</p> </td>
<td nowrap>
<p align="left">
<textarea name="Message" rows=5 cols=35></textarea>
</p></td>
</tr>
<tr>
<td nowrap align="right" valign="top">
<p class="label">Email List</p> </td>
<td nowrap>
<p class="labelmail">
<input type=checkbox name=Category id="checkid1" value=1 checked="checked" ><label for="checkid1">Mailing list</label><br>
</p> </td>
</tr>
<tr>
<td nowrap> </td>
<td nowrap>
<input
type="submit"
value="Click Me"
onclick="return submitOthers(this.form)"></td></tr>
</p>
</td>
</tr>
<tr>
<td nowrap> </td>
<td nowrap>
<p class="privacy">We will never rent or sell your personal information. </p> </td>
</tr>
</table>
<input type="hidden" name="Type" value="add">
</form>
<tr><td colspan=2 align=center><small>A <font color=red>*</font> indicates a field is required</small>
</td></tr>
</table>
<script type="text/javascript" language="JavaScript">
<!-- Copyright 2006-2007 Bontrager Connection, LLC
var submitURL = new Array();
submitURL[0] = 'gdform.asp';
submitURL[1] = 'mailinglist/default.asp?add';
var selectFieldOpen = false;
var selectFieldName = '';
var blockedHandled = false;
var returnValue = true;
var fields = new Array();
var popupsMade = 0;
function generateString(kk,vv,type,m) {
if(m == 'g') { return escape(kk) + '=' + escape(vv); }
return '<input type="' + type + '" name="' + kk + '" value="' + vv + '">';
}
function closeSelectField(m) {
if(m == 'g') { return; }
if(selectFieldOpen == false) { return; }
selectFieldOpen = false;
fields.push('</select>');
}
function openSelectField(kk,type,m) {
if(m == 'g') { return; }
if(selectFieldOpen == true) {
if(selectFieldName != kk) { closeSelectField(m); }
else { return; }
}
selectFieldName = kk;
selectFieldOpen = true;
var selectmultipleattribute = new String();
if(type.substr(7,8) == 'multiple') { selectmultipleattribute = ' multiple'; }
fields.push('<select name="' + kk + '"' + selectmultipleattribute +'>');
}
function straightValue(fptr,digit,type,m) {
closeSelectField(m);
var k = fptr[digit].name;
var v = fptr[digit].value;
var s = generateString(k,v,type,m);
fields.push(s);
}
function checkValue(k,v,type,m) {
closeSelectField(m);
var s = generateString(k,v,type,m);
fields.push(s);
}
function processSelect(fptr,digit,type,m) {
openSelectField(fptr[digit].name,type,m);
for(var ii = 0; ii < fptr[digit].length; ii++) {
var checked = new String();
if(fptr[digit][ii].selected == true) { checked = ' checked'; }
if(m == 'g') { if(checked.length > 0) { fields.push(escape(fptr[digit].name) + '=' + escape(fptr[digit][ii].value)); } }
else { fields.push('<option value="' + fptr[digit][ii].value + '"' + checked + '>' + fptr[digit][ii].text + '</option>'); }
}
}
function processText(fptr,digit,type,m) { straightValue(fptr,digit,type,m); }
function processHidden(fptr,digit,type,m) { straightValue(fptr,digit,type,m); }
function processFile(fptr,digit,type,m) { straightValue(fptr,digit,type,m); }
function processSubmit(fptr,digit,type,m) { straightValue(fptr,digit,type,m); }
function processTextarea(fptr,digit,type,m) {
if(m == 'g') { fields.push(escape(fptr[digit].name) + '=' + escape(fptr[digit].value)); }
else { fields.push('<textarea name="' + fptr[digit].name + '">' + fptr[digit].value + '</textarea>'); }
}
function processRadio(fptr,digit,type,m) {
if(fptr[digit].checked == true) { checkValue(fptr[digit].name,fptr[digit].value,type,m); }
}
function processCheckbox(fptr,digit,type,m) {
if(fptr[digit].checked == true) { checkValue(fptr[digit].name,fptr[digit].value,type,m); }
}
function processSelectOne(fptr,digit,type,m) { processSelect(fptr,digit,type,m); }
function processSelectMultiple(fptr,digit,type,m) { processSelect(fptr,digit,type,m); }
function submitTheForm(fptr,url) {
var m = fptr.method.toLowerCase();
m = m.substr(0,1);
if(m == 'p') {
var s = new String('<form name="fn1170700036nf" method="POST" ');
// if(fptr.enctype.length > 0) { s += 'enctype="' + fptr.enctype + '" '; }
s += 'action="' + url + '">';
fields.push(s);
}
for(var i = 0; i < fptr.length; i++) {
var type = fptr[i].type;
if(type == 'select') { type = 'select-one'; }
if(type == 'text' ) { processText(fptr,i,type,m); continue; }
if(type == 'textarea' ) { processTextarea(fptr,i,type,m); continue; }
if(type == 'hidden' ) { processHidden(fptr,i,type,m); continue; }
if(type == 'radio' ) { processRadio(fptr,i,type,m); continue; }
if(type == 'checkbox' ) { processCheckbox(fptr,i,type,m); continue; }
if(type == 'select-one' ) { processSelectOne(fptr,i,type,m); continue; }
if(type == 'select-multiple') { processSelectMultiple(fptr,i,type,m); continue; }
if(type == 'file' ) { processFile(fptr,i,type,m); continue; }
if(type == 'submit' ) { processSubmit(fptr,i,type,m); continue; }
}
if(m == 'p') { fields.push('</form>'); }
if(m == 'g') {
var dest = new String(url + '?');
dest += fields.join('&');
var newin = window.open('','','width=100,height=100');
newin.document.writeln('<html><body>');
newin.document.writeln('<sc' + 'ript>');
newin.document.writeln('window.opener.popupsMade++ ;');
newin.document.writeln('window.location.href="' + dest + '";');
newin.document.writeln('</sc' + 'ript>');
newin.document.writeln('</body></html>');
self.focus();
fields.length = 0;
return;
}
var dest = fields.join('\n');
var newin = window.open('','','width=100,height=100');
newin.document.writeln('<html><body>');
newin.document.writeln(dest);
newin.document.writeln('<sc' + 'ript>');
newin.document.writeln('window.opener.popupsMade++ ;');
newin.document.writeln('document.fn1170700036nf.su bmit();');
newin.document.writeln('</sc' + 'ript>');
newin.document.writeln('</body></html>');
self.focus();
fields.length = 0;
}
function HandleBlocked() {
if(blockedHandled == true) { return; }
blockedHandled = true;
}
function submitOthers(f) {
popupsMade = 0;
var popupsTried = 0;
for(var iii = 0; iii < submitURL.length; iii++) {
if(submitURL[iii]) {
submitTheForm(f,submitURL[iii]);
popupsTried++;
if(popupsMade < popupsTried) { HandleBlocked(); }
}
if(returnValue == false) { break; }
}
popupsMade = 0;
popupsTried = 0;
return returnValue;
}
//-->
</script>
<p class="relatedtasks">Related tasks:</p>
<a class="related" href="mailinglist/remove.asp">Remove yourself from an email list</a><br>
<a class="relatedback" href="http://www.yoursite.com">Return to the home page</a><br>
<a class="related" href="mailinglist/login.asp">Administrator login</a><br>
<br>
</body></html>
Last edited by Shizoku; 02-09-2007 at 04:26 PM..
|