ubh
01-10-2008, 09:28 PM
I have two scripts.
The first one is to require certain fields I have in a form are filled out.
The second one is to open a new window with height/width control of the new window.
My problem is that when the scripts are running as separate scripts I get the "fields required script" to pop up its message
if a field is not filled out, but also the new window pop up too.
The process should be
A)if you get notified a field is not filled out you must fill it out before the new window pops up.
Not
B)Pop up the new window if you get a field needs to be filled out...
So my thoughts were to combine the scripts together so that the window pops up when my field validation is complete.. but I am having trouble.. and this is why I am here.
how would I combine these two?
Script One (Form Fields Required)
var FormName = "nominationForm";
var RequiredFields = "Your_First_Name,Your_Last_Name,Your_Title,Your_Address,Your_City,Your_State,Your_Zip,Your_Telephone,Your_Email,Confirm_Email,Your_School,Your_Principal,relation ship,Their_First_Name,Their_Last_Name,Their_Title,Their_District,Their_School,Their_Address,Their_City,Their_State,Their_Zip,How_Many_Years";
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 Two (Open New Window with Width/Height Control)
function sendme()
{
window.open("","myNewWin","width=500,height=300,toolbar=0");
var a = window.setTimeout("document.nominationForm.submit();",500);
}
The first one is to require certain fields I have in a form are filled out.
The second one is to open a new window with height/width control of the new window.
My problem is that when the scripts are running as separate scripts I get the "fields required script" to pop up its message
if a field is not filled out, but also the new window pop up too.
The process should be
A)if you get notified a field is not filled out you must fill it out before the new window pops up.
Not
B)Pop up the new window if you get a field needs to be filled out...
So my thoughts were to combine the scripts together so that the window pops up when my field validation is complete.. but I am having trouble.. and this is why I am here.
how would I combine these two?
Script One (Form Fields Required)
var FormName = "nominationForm";
var RequiredFields = "Your_First_Name,Your_Last_Name,Your_Title,Your_Address,Your_City,Your_State,Your_Zip,Your_Telephone,Your_Email,Confirm_Email,Your_School,Your_Principal,relation ship,Their_First_Name,Their_Last_Name,Their_Title,Their_District,Their_School,Their_Address,Their_City,Their_State,Their_Zip,How_Many_Years";
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 Two (Open New Window with Width/Height Control)
function sendme()
{
window.open("","myNewWin","width=500,height=300,toolbar=0");
var a = window.setTimeout("document.nominationForm.submit();",500);
}