Advanced Search

Results 1 to 3 of 3

Thread: Required Feild Script + Form Submit New Window HELP!

  1. #1
    Join Date
    Aug 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Required Feild Script + Form Submit New Window HELP!

    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)
    Code:
    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,relationship,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)
    Code:
    function sendme() 
    { 
        window.open("","myNewWin","width=500,height=300,toolbar=0"); 
        var a = window.setTimeout("document.nominationForm.submit();",500); 
    }

  2. #2
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    Code:
    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,relationship,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]; }
    if (message != null) {
    alert(message);
    return false;
    } else {
    sendme();
    }
    
    
    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;
    }
    function sendme() 
    { 
        window.open("","myNewWin","width=500,height=300,toolbar=0"); 
        var a = window.setTimeout("document.nominationForm.submit();",500); 
    }
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@ /\/\@|{
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  3. #3
    Join Date
    Aug 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi Master_Script_Maker..

    Thank you SOOO MUCH for taking the time to help me with this its been bugging me.

    I tried your version and at first I got an error from IE7 that said I needed to add a "}" at the very end of the script so I did and I don't get an error upon the page loading.. how ever I do get one when I click submit now. It says the error is on line 242 but all that is their is a form input feild.. I am confused.

    Here is my page in whole, Please can you help me I feel I am soooo close to getting this!

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Reaching ALL Youth&reg;</title>
    </head>
    <script type="text/javascript" language="JavaScript">
    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,relationship,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]; }
    if (message != null) {
    alert(message);
    return false;
    } else {
    sendme();
    }
    
    
    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;
    }
    function sendme() 
    { 
        window.open("","myNewWin","width=500,height=300,toolbar=0"); 
        var a = window.setTimeout("document.nominationForm.submit();",500); 
    }
    }
    </script>
    <body onload="changeBox3()">
    <div id="3">
            <br /><br />
            <form method="POST" action="nominationSubmit.php" name="nominationForm" onsubmit="return ValidateRequiredFields();" target="myNewWin">
            <fieldset>
                <legend><strong>Nominator Contact Information</strong></legend>
                <blockquote>
                <input  name="Your_First_Name" type="text" /> First Name<br />
                <input  name="Your_Last_Name" type="text" /> Last Name<br />
                <input  name="Your_Title" type="text" /> Title (if applicable)<br />
                <input  name="Your_Address" type="text" /> Address<br />
                <input  name="Your_City" type="text" /> City<br />
                <input  name="Your_State" type="text" /> State<br />
                <input  name="Your_Zip" type="text" /> Zip<br />
                <input  name="Your_Telephone" type="text" /> Telephone<br />
                <input  name="Your_Email" type="text" /> Email<br />
                <input  name="Confirm_Email" type="text" /> Email Confirmed<br />
                <input  name="Your_School" type="text" /> High School/Organization<br />
                <input  name="Your_Principal" type="text" /> Principal Name<br />
                </blockquote><br /><br />
            </fieldset>
            <fieldset>
                <legend><strong>Relationship to Nominee (Please check the appropriate box)</strong></legend>    
                <blockquote>
    			  <select name="relationship">
    				<option selected="selected"></option>
    				<option value="School Administrator">School Administrator</option>
    				<option value="Staff/Faculty">Staff/Faculty</option>
    				<option value="Student's Parent">Student's Parent</option>
    				<option value="Student">Student</option>
    			  </select><br /><br />
                 
                  And/or Other:
                  <input type="checkbox" onclick="javascript:InsertContent('other');"/>
    			  
                  <div id="other" style="display:none;">
    			  If other please tell us more: 
                  <input name="otherDescipt"/>
                  </div>
                  
    			</blockquote>
                <br />
    
            </fieldset>
            <fieldset>
                <legend><strong>Nominee Contact Information</strong></legend>
                <blockquote>
                <input name="Their_First_Name" type="text" /> First Name<br />
                <input name="Their_Last_Name" type="text" /> Last Name<br />
                <input name="Their_Title" type="text" /> Title<br />
                <input name="Their_District" type="text" /> School District<br />
                <input name="Their_School" type="text" /> High School<br />
                <input name="Their_Address" type="text" /> School Address<br />
                <input name="Their_City" type="text" /> City<br />
                <input name="Their_State" type="text" /> State<br />
                <input name="Their_Zip" type="text" /> Zip<br /><br />
                Number of years as a college counselor: <input name="How_Many_Years" type="text" /><br />                   
                </blockquote>
            </fieldset>
            <br />
            <input style="margin-left:40em; margin-bottom:2em;" type="submit" value="Next Step" onclick="sendme();"/>
            </form>
            </div>
    </body>
    </html>
    PS sorry for flooding the page

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •