Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JS Validation & Object Problems (Extremely Urgent) 1

Status
Not open for further replies.

rmz8

Programmer
Aug 24, 2000
210
US
i'm posting this again because i haven't received a response and this is perhaps the most imporant project of my life. please help.

i'm in a huge crunch. i've created this entire project for free for my school, and i have to present it to the faculty, and now all of these errors are coming up i'd really appreciate your help

well, my javascript problem is two fold. first, let me show you all of the code:

<SCRIPT language=&quot;JavaScript&quot;>
<!--

function checkSelects(form) {

select1 = form.Resource_Type
select2 = form.Subject_Area
select3 = form.Grade_Level

if(select1.value=='xyz') {
alert('Please select a resource type.')
return false;
}
if(select2.value=='xyz') {
alert('Please select a subject area for your resource.')
return false;
}

if(select3.value=='xyz') {
alert('Please select a grade level for your resource.')
return false;
}
return true;
}

function validation_function() {

if (!document.frm.Resource_Description.value){
alert('Please enter a description for your resource.');
return false;
}


<cfloop index=&quot;x&quot; from=&quot;1&quot; to=#form.fileuploads#>
crap = frm.upfile#x#.value;
arr = crap.split(&quot;.&quot;);
reg = /^((pdf)|(PDF)|(gif)|(GIF)|(htm)|(HTM)|(html)|(HTML)|(jpeg)|(JPEG)|(jpg)|(JPG)|(mdb)|(MDB)|(xls)|(XLS)|(ppt)|(PPT)|(doc)|(DOC)|(txt)|(TXT))$/;
if(reg.test(arr[arr.length - 1]))
{

}
else
{
alert(&quot;You can only upload Adobe PDF, GIF, HTML, JPEG, Microsoft Access, Microsoft Excel, Microsoft PowerPoint, Microsoft Word, and Plain Text files. Please select another file.&quot;);
return false;
}

</cfloop>
}
//-->

</SCRIPT>

If you don't know ColdFusion, basically what the CFLOOP does is creates the code specified code (within the CFLOOP tags) as many times as necessary (thus for as many file upload fields there are). The first function is called by:

<INPUT TYPE=&quot;submit&quot; VALUE=&quot;Submit&quot; onClick=&quot;return checkSelects(this.form);&quot;>

The second function is called by onsubmit:

<CFFORM action=&quot;add_update.cfm&quot; method=&quot;post&quot; name=&quot;frm&quot; enctype=&quot;multipart/form-data&quot; onsubmit=&quot;return validation_function()&quot;>

The first function works well in Internet Explorer, but in Netscape the code, which doesn't generate an error, is just skipped (or so it seems).

As for the second function (which validates that a file field is filled in with only the specified formats; you helped create this, acutally), I cannot get it to work in either Internet Explorer or Netscape. I've tried changing &quot;crap&quot; to numerous different things (the name of the form is frm, so i tried it with that, as shown above and it still doesn't work). With the current code IE outputs &quot;frm.upfile1.value is not an object or null.&quot; In Netscape it says &quot;frm is not defined.&quot; However, I've tried so many different formats using form, frm, leaving out value, etc. and nothing works.

If you would like to see the page &quot;live&quot; on the server go to:


Then login with the UN:

jbernhardt

PW:

test

Then fill in an amount of files to upload. After clicking Submit you will be taken to the page with all of the errors. I'm using IE 5.5 and Netscape 4.7 and 6.

thanks so much in advance for your help.

Ryan ;-]


Ryan ;-]
 
Thanks so much, Rydel! Here is the code for the ENTIRE page (I figure you can just cut and paste it to make an identical HTML page):

Code:
<!--©2000-2001, ZEAL network, INC.  All Rights Reserved

It is illegal to use this software without the express written consent of ZEAL network, INC. and Ryan Zacharia, the product's developer.
--> 

<TITLE>GATSBY for Lynbrook Public School District</TITLE>
<HTML>
<HEAD>

<META HTTP-EQUIV=&quot;Content-Type&quot; CONTENT=&quot;text/html; charset=iso-8859-1&quot;>
<!--Check for password in URL --> 

<!--Authorization check --> 

<!--Run query to get user information --> 


<!--Checks if URL primary key value is present --> 



<!--Sets variables for primary key not being present --> 










<TITLE>ZEAL network's GATSBY: Add Resource</TITLE>
  <SCRIPT language=&quot;JavaScript&quot;>
<!--

   function checkSelects(form) {
    
    select1 = form.Resource_Type
    select2 = form.Subject_Area
    select3 = form.Grade_Level

    if(select1.value=='xyz') {
        alert('Please select a resource type.')
        return false;
        }
    if(select2.value=='xyz') {
        alert('Please select a subject area for your resource.')
        return false;
        }

    if(select3.value=='xyz') {
        alert('Please select a grade level for your resource.')
        return false;
        }
    return true;      
}

function validation_function() {

if (!document.frm.Resource_Description.value){
alert('Please enter a description for your resource.');
return false;
}



crap = frm.upfile1.value;
    arr  = crap.split(&quot;.&quot;);
    reg = /^((pdf)|(PDF)|(gif)|(GIF)|(htm)|(HTM)|(html)|(HTML)|(jpeg)|(JPEG)|(jpg)|(JPG)|(mdb)|(MDB)|(xls)|(XLS)|(ppt)|(PPT)|(doc)|(DOC)|(txt)|(TXT))$/; 
    if(reg.test(arr[arr.length - 1]))
    {
        
    }
    else
    {
        alert(&quot;You can only upload Adobe PDF, GIF, HTML, JPEG, Microsoft Access, Microsoft Excel, Microsoft PowerPoint, Microsoft Word, and Plain Text files.  Please select another file.&quot;);
return false;
    }
	

}
//-->

</SCRIPT>
  

<script LANGUAGE=JAVASCRIPT TYPE=&quot;text/javascript&quot; >

<!--


function _CF_onError(form_object, input_object, object_value, error_message)
    {
	alert(error_message);
       	return false;	
    }



function _CF_hasValue(obj, obj_type)
    {
    if (obj_type == &quot;TEXT&quot; || obj_type == &quot;PASSWORD&quot;)
	{
    	if (obj.value.length == 0) 
      		return false;
    	else 
      		return true;
    	}
    else if (obj_type == &quot;SELECT&quot;)
	{
        for (i=0; i < obj.length; i++)
	    	{
		if (obj.options[i].selected)
			return true;
		}

       	return false;	
	}
    else if (obj_type == &quot;SINGLE_VALUE_RADIO&quot; || obj_type == &quot;SINGLE_VALUE_CHECKBOX&quot;)
	{

		if (obj.checked)
			return true;
		else
       		return false;	
	}
    else if (obj_type == &quot;RADIO&quot; || obj_type == &quot;CHECKBOX&quot;)
	{

        for (i=0; i < obj.length; i++)
	    	{
		if (obj[i].checked)
			return true;
		}

       	return false;	
	}
	}


function  _CF_checkfrm(_CF_this)

    {

    if  (!_CF_hasValue(_CF_this.Resource_Title, &quot;TEXT&quot; )) 

        {

        if  (!_CF_onError(_CF_this, _CF_this.Resource_Title, _CF_this.Resource_Title.value, &quot;Please enter a title for your resource.&quot;))

            {

            return false; 

            }

        }


return validation_function()

    return true;

    }


//-->

</script>

</HEAD>


<BODY BGCOLOR=&quot;FFFFFF&quot;>
  <DIV ALIGN=&quot;CENTER&quot;>
    <P><IMG SRC=&quot;[URL unfurl="true"]http://www.lynbrook.k12.ny.us/cfm/student_resources/gatsby/images/logo.gif&quot;><BR>[/URL]
      <FONT FACE=&quot;Arial, Helvetica, sans-serif&quot;><I><B><U><FONT SIZE=&quot;4&quot;>Lynbrook Public School District</FONT></U></B></I></FONT></P>
    <br>
  </DIV>

  <H2><FONT FACE=&quot;Arial, Helvetica, sans-serif&quot;><U>Add Resource</U> <B><FONT FACE=&quot;Arial, Helvetica, sans-serif&quot; SIZE=&quot;2&quot;></FONT></B><U><B><FONT FACE=&quot;Arial, Helvetica, sans-serif&quot; SIZE=&quot;2&quot;>[<A HREF=&quot;index.cfm&quot;>Go 
    back</A>] </FONT></B></U></FONT></H2>
<FORM NAME=&quot;frm&quot; ACTION=&quot;add_update.cfm&quot; METHOD=POST onSubmit=&quot;return _CF_checkfrm(this)&quot; ENCTYPE=&quot;multipart/form-data&quot;>

    <INPUT type=&quot;hidden&quot; name=&quot;Teacher&quot; value=&quot;7&quot;>
  
    <TABLE BORDER=&quot;0&quot;>
      <TR> 
        <TD HEIGHT=&quot;7&quot; VALIGN=&quot;TOP&quot; COLSPAN=&quot;2&quot;><I><B><FONT SIZE=&quot;2&quot; FACE=&quot;Arial, Helvetica, sans-serif&quot;></FONT></B></I><FONT FACE=&quot;Arial, Helvetica, sans-serif&quot; SIZE=&quot;2&quot;><B>Resource 
          Title:</B></FONT></TD>
        <TD HEIGHT=&quot;7&quot; WIDTH=&quot;84%&quot;> <FONT FACE=&quot;Arial, Helvetica, sans-serif&quot; SIZE=&quot;2&quot;> 
          <INPUT TYPE=&quot;TEXT&quot; NAME=&quot;Resource_Title&quot; VALUE=&quot;&quot; SIZE=&quot;10&quot;>
          </FONT></TD>
      </TR>
      <TR> 
        <TD HEIGHT=&quot;2&quot; VALIGN=&quot;TOP&quot; COLSPAN=&quot;2&quot;><FONT FACE=&quot;Arial, Helvetica, sans-serif&quot; SIZE=&quot;2&quot;><B>Resource 
		  Type:</B></FONT><BR>
		  <FONT FACE=&quot;Arial, Helvetica, sans-serif&quot; SIZE=&quot;1&quot;>If you are uploading 
		  a web page with images and other files make sure the type selected is 
		  HTML.</FONT></TD>
        <TD HEIGHT=&quot;2&quot; WIDTH=&quot;84%&quot;> 
          <SELECT NAME=&quot;Resource_Type&quot;>
            <OPTION VALUE=&quot;xyz&quot; SELECTED>--SELECT AN OPTION--</OPTION>
            <OPTION VALUE=&quot;xyz&quot;>+-+-+-+-+-+-+-+</OPTION>
            <OPTION VALUE=&quot;Adobe PDF&quot;>Adobe PDF</OPTION>
            <OPTION VALUE=&quot;GIF&quot;>GIF</OPTION>
            <OPTION VALUE=&quot;HTML&quot;>HTML</OPTION>
<OPTION VALUE=&quot;JPEG&quot;>JPEG</OPTION>
<OPTION VALUE=&quot;Microsoft Access&quot;>Microsoft Access</OPTION>
            <OPTION VALUE=&quot;Microsoft Excel&quot;>Microsoft Excel</OPTION>
            <OPTION VALUE=&quot;Microsoft PowerPoint&quot;>Microsoft PowerPoint</OPTION>
            <OPTION VALUE=&quot;Microsoft Word&quot;>Microsoft Word</OPTION>
            <OPTION VALUE=&quot;Plain Text&quot;>Plain Text</OPTION>
          </SELECT>
        </TD>
      </TR>
      <TR> 
        <TD HEIGHT=&quot;2&quot; VALIGN=&quot;TOP&quot; COLSPAN=&quot;2&quot;><FONT FACE=&quot;Arial, Helvetica, sans-serif&quot; SIZE=&quot;2&quot;><B>Subject 
          Area:</B></FONT></TD>
        <TD HEIGHT=&quot;2&quot; WIDTH=&quot;84%&quot;> 
          <SELECT NAME=&quot;Subject_Area&quot;>
            <OPTION VALUE=&quot;xyz&quot; SELECTED>--SELECT AN OPTION--</OPTION>
            <OPTION VALUE=&quot;xyz&quot;>+-+-+-+-+-+-+-+</OPTION>
            <OPTION VALUE=&quot;Computers&quot;>Computers</OPTION>
            <OPTION VALUE=&quot;Guidance&quot;>Guidance</OPTION>
            <OPTION VALUE=&quot;English&quot;>English</OPTION>
            <OPTION VALUE=&quot;Family & Consumer Sciences&quot;>Family & Consumer Sciences</OPTION>
            <OPTION VALUE=&quot;Fine Arts
&quot;>Fine Arts</OPTION>
            <OPTION VALUE=&quot;Foreign Language&quot;>Foreign Language</OPTION>
            <OPTION VALUE=&quot;Mathematics&quot;>Mathematics</OPTION>
            <OPTION VALUE=&quot;Music&quot;>Music</OPTION>
            <OPTION VALUE=&quot;Physical Education&quot;>Physical Education</OPTION>
            <OPTION VALUE=&quot;Science&quot;>Science</OPTION>
            <OPTION VALUE=&quot;Social Studies&quot;>Social Studies</OPTION>
            <OPTION VALUE=&quot;Special Educaton&quot;>Special Educaton</OPTION>
          </SELECT>
        </TD>
      </TR>
      <TR> 
        <TD HEIGHT=&quot;2&quot; VALIGN=&quot;TOP&quot; COLSPAN=&quot;2&quot;><FONT FACE=&quot;Arial, Helvetica, sans-serif&quot; SIZE=&quot;2&quot;><B>Grade 
		  Level:</B></FONT></TD>
        <TD HEIGHT=&quot;2&quot; WIDTH=&quot;84%&quot;> 
          <SELECT NAME=&quot;Grade_Level&quot;>

            <OPTION VALUE=&quot;xyz&quot; SELECTED>--SELECT AN OPTION--</OPTION>
            <OPTION VALUE=&quot;xyz&quot;>+-+-+-+-+-+-+-+</OPTION>
            <OPTION VALUE=&quot;1&quot;>1st Grade</OPTION>
            <OPTION VALUE=&quot;2&quot;>2nd Grade</OPTION>
            <OPTION VALUE=&quot;3&quot;>3rd Grade</OPTION>
            <OPTION VALUE=&quot;4&quot;>4th Grade</OPTION>
            <OPTION VALUE=&quot;5&quot;>5th Grade</OPTION>
            <OPTION VALUE=&quot;6&quot;>6th Grade</OPTION>
            <OPTION VALUE=&quot;7&quot;>7th Grade</OPTION>
            <OPTION VALUE=&quot;8&quot;>8th Grade</OPTION>
            <OPTION VALUE=&quot;9&quot;>9th Grade</OPTION>
            <OPTION VALUE=&quot;10&quot;>10th Grade</OPTION>
            <OPTION VALUE=&quot;11&quot;>11th Grade</OPTION>
            <OPTION VALUE=&quot;12&quot;>12th Grade</OPTION>
            <OPTION VALUE=&quot;13&quot;>Mixed</OPTION>
          </SELECT>
        </TD>
      </TR>
      <TR> 
        <TD HEIGHT=&quot;2&quot; VALIGN=&quot;TOP&quot; COLSPAN=&quot;2&quot;> 
          <P><FONT FACE=&quot;Arial, Helvetica, sans-serif&quot; SIZE=&quot;2&quot;><B>Resource Description:</B></FONT></P>
          </TD>
        <TD HEIGHT=&quot;2&quot; WIDTH=&quot;84%&quot;> 
          <TEXTAREA NAME=&quot;Resource_Description&quot; COLS=&quot;70&quot; ROWS=&quot;8&quot;></TEXTAREA>
        </TD>
      </TR>
      
      <TR> 
        <TD HEIGHT=&quot;2&quot; WIDTH=&quot;16%&quot; VALIGN=&quot;TOP&quot; COLSPAN=&quot;2&quot;><FONT FACE=&quot;Arial, Helvetica, sans-serif&quot; SIZE=&quot;2&quot;><B>Files: 
          </B></FONT><BR>
          <FONT FACE=&quot;Arial, Helvetica, sans-serif&quot; SIZE=&quot;1&quot;>You can upload up 
          to 1 file(s). If you are uploading a web page make 
          sure that the HTML file is the last file in the upload list.</FONT></TD>
        <TD HEIGHT=&quot;2&quot; WIDTH=&quot;84%&quot;> 
          <INPUT type=&quot;hidden&quot; name=&quot;numberInputs&quot; value=&quot;1&quot;>
          

              <P><INPUT TYPE=&quot;file&quot; NAME=&quot;upFile1&quot;></P>


          </TD>
      </TR>
      <TR> 
        <TD HEIGHT=&quot;2&quot; COLSPAN=&quot;3&quot;> <FONT FACE=&quot;Arial, Helvetica, sans-serif&quot; SIZE=&quot;2&quot;> 
          <INPUT TYPE=&quot;submit&quot; VALUE=&quot;Submit&quot; onClick=&quot;return checkSelects(this.form);&quot;>
          <INPUT TYPE=&quot;RESET&quot; NAME=&quot;Reset&quot; VALUE=&quot;Reset&quot;>
          </FONT></TD>
      </TR>
    </TABLE>
</FORM>
<!--Run query to get user information --> 


<DIV ALIGN=&quot;CENTER&quot;> 
  <TABLE BORDER=&quot;0&quot;>
    <TR> 
      <TD><FONT SIZE=&quot;2&quot; FACE=&quot;Arial, Helvetica, sans-serif&quot;>©2000-2001, 
        <I>ZEAL</I> network, INC.</FONT> </TD>
      <TD><FONT FACE=&quot;Arial, Helvetica, sans-serif&quot; SIZE=&quot;2&quot;><A HREF=&quot;logout.cfm&quot;><B><I>LOGOUT</I></B></A></FONT></TD>
    </TR>
  </TABLE>
</DIV>



</BODY>
</HTML>

Ryan ;-]
 
Ok, well I got the form to submit -- It took two things:

Here's both of them on one line:

crap = document.frm.upFile1.value;

notice I prefaced your object name with document.

and fixed the case on your upFile1 -- you had it as upfile1... it submitted with no errors once I changed that line.

good luck! :)
Paul Prewett
 
Paul,

You are a lifesaver. You have helped me out so much! I can't believe it was such a small problem.

One other thing though (I hate to be such a nudge). In Netscape, the JavaScript code that makes a user have to select something from the select boxes doesn't work (it just skips over the code. Here is that code (Which works in IE):
Code:
   function checkSelects(form) {
    
    select1 = form.Resource_Type
    select2 = form.Subject_Area
    select3 = form.Grade_Level

    if(select1.value=='xyz') {
        alert('Please select a resource type.')
        return false;
        }
    if(select2.value=='xyz') {
        alert('Please select a subject area for your resource.')
        return false;
        }

    if(select3.value=='xyz') {
        alert('Please select a grade level for your resource.')
        return false;
        }
    return true;      
}

It is called by this:

Code:
<INPUT TYPE=&quot;submit&quot; VALUE=&quot;Submit&quot; onClick=&quot;return checkSelects(this.form);&quot;>

Ryan ;-]
 
Well, I'm not familiar with all the _cf_checkthis and _cf_checkthat --

but here's what I found -- maybe it will set you on the path to your solution --

It appears as though NutScrape is getting confused when you are saying (this) in one spot and (this.form) in the other spot -- and IE likes it like you have it --

I tried to change it around, and then IE started cursing at me, too, while Netscape just did nothing --

So what's the solution??? I would do your entire form validation inside of one function -- instead of having one return a value for the submit button, and then having a <form onSubmit> for the other half of validation --

I think that's what's causing the problem -- just roll it all into one nice validation function -- and maybe even don't send it the this.anything -- just have it check for document.frm.elementName.value all the way down the line.

let me know if you get it worked out or not -- we can go a little deeper if we have to.

:)
Paul Prewett
 
The CF JavaScript is generated from ColdFusion's own validation script, and this I don't even work with any of the source code for that (it is automatically generated when you use several ColdFusion validations).

I tried the following:

function checkSelects() {

select1 = document.frm.Resource_Type
select2 = document.frm.Subject_Area
select3 = document.frm.Grade_Level

if(select1.value=='xyz') {
alert('Please select a resource type.')
return false;
}
if(select2.value=='xyz') {
alert('Please select a subject area for your resource.')
return false;
}

if(select3.value=='xyz') {
alert('Please select a grade level for your resource.')
return false;
}
return true;
}

And including it in the onSubmit function in the FORM tag like so:

onsubmit=&quot;return validation_function();return checkSelects();&quot;

It doesn't work, however. What can I do? Thanks so much for your help, Paul.

Ryan ;-]
 
Like you said, I altered the code into one function, like so:
Code:
<!--

function validation_function() {

if (!document.frm.Resource_Description.value){
alert('Please enter a description for your resource.');
return false;
}
    if(document.frm.Resource_Type.value=='xyz') {
        alert('Please select a resource type.')
        return false;
        }
    if(document.frm.Subject_Area.value=='xyz') {
        alert('Please select a subject area for your resource.')
        return false;
        }

    if(document.frm.Grade_Level.value=='xyz') {
        alert('Please select a grade level for your resource.')
        return false;
        }  


crap = document.frm.upFile1.value;
    arr  = crap.split(&quot;.&quot;);
    reg = /^((pdf)|(PDF)|(gif)|(GIF)|(htm)|(HTM)|(html)|(HTML)|(jpeg)|(JPEG)|(jpg)|(JPG)|(mdb)|(MDB)|(xls)|(XLS)|(ppt)|(PPT)|(doc)|(DOC)|(txt)|(TXT))$/; 
    if(reg.test(arr[arr.length - 1]))
    {
        
    }
    else
    {
        alert(&quot;You can only upload Adobe PDF, GIF, HTML, JPEG, Microsoft Access, Microsoft Excel, Microsoft PowerPoint, Microsoft Word, and Plain Text files.  Please select another file.&quot;);
return false;
    }
        

}
//-->
[code]

This function is called to by the following:

[code]<INPUT TYPE=&quot;submit&quot; VALUE=&quot;Submit&quot; onclick=&quot;return validation_function();&quot;>

Everything functions in IE perfectly, but Netscape 4.7 AND Netscape 6 simply override the part of the validation function that attempts to validate the select boxes.

Ryan ;-]
 
Man, I can't get it --

I'm stumped. I've sat here playing with it for over an hour now, and just don't know what else to try. Don't you just love NN???

My suggestion (even though it's off topic) would be to try and post over in the HTML forum, and maybe someone there will help.

If not, then another one of the people over here in this forum is going to have to step up to bat here. I feel pretty confident that they will.

I'd bet you'll have an answer before noon tomorrow -- I'm just sorry I couldn't help more.

good luck
paul
 
Paul,

Thanks so much for your help. Ironically enough, several of the members of this forum helped to write that code.

I'm going to post this in the HTML forum now, and hopefully I will have a response before the end of today (and before my presentation of this software!).

Once again, thank you for your help, it is greatly appreciated.

Ryan ;-]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top