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!

Javascript Validation... Error with Netscape

Status
Not open for further replies.

aspnewbee

MIS
Jul 11, 2004
34
US
Hi... I have this javascript validation for an upload feature I created on an ASP page... the validation works fine on IE... but the submit button doesn't even click or there is no activity when the submit button is clicked but the file get UPLOADED in the background...on NETSCAPE 7.1 (only on PCs) Netscape on MACs works fine. As you can see the validation should work for the paper title and the file being uploaded... Can anyone help me with this please? Thanks a lot.

HERE IS THE CODE:

Code:
<script language="javascript">

function fun () {
	
     var path = document.upform.blob.value;
     var pattern = /\s/;
     file = path.split("\\");
     file.reverse();
     if (pattern.test(file[0])) {
     alert ("Your filename includes spaces. Please rename your file per the guidelines on this page and try again.");
     } else if (document.upform.docName.value.length == 0){
     alert("Please enter the Paper Title");}
     
     else {LimitAttach(this.upform, this.upform.blob.value);} //{document.upform.submit();}
	
}
extArray = new Array(".htm", ".html", ".pdf", ".doc");
function LimitAttach(form, file) {
allowSubmit = false;
if (!file) return;
while (file.indexOf("\\") != -1)
file = file.slice(file.indexOf("\\") + 1);
ext = file.slice(file.indexOf(".")).toLowerCase();
for (var i = 0; i < extArray.length; i++) {
if (extArray[i] == ext) { allowSubmit = true; break; }
}
if (allowSubmit) form.submit();
else
alert("Please only submit files that end in:  " 
+ (extArray.join("  ")) + "\nPlease select a new "
+ "file and try again. Thank you.");
}
</script>
 
It's a good idea to surround the blocks of code with curly braces '{}' in IF/ELSE statements, while loops, etc. even when there is only a single statement.

Code:
<script language="javascript">

function fun ()
{ 
 var path = document.upform.blob.value;
 var pattern = /\s/;
 file = path.split("\\");
 file.reverse();
 if (pattern.test(file[0])) {
     alert ("Your filename includes spaces. Please rename your file per the guidelines on this page and try again.");
 }
 else if (document.upform.docName.value.length == 0)
 {
   alert("Please enter the Paper Title");
 }
 else
 {
 LimitAttach(this.upform, this.upform.blob.value);
 } //{document.upform.submit();}
    
}

extArray = new Array(".htm", ".html", ".pdf", ".doc");

function LimitAttach(form, file) 
{
 allowSubmit = false;
 if (!file)
 {
 return;
  }

 while (file.indexOf("\\") != -1)
 {
  file = file.slice(file.indexOf("\\") + 1);
  ext = file.slice(file.indexOf(".")).toLowerCase();
  for (var i = 0; i < extArray.length; i++) 
  {
    if (extArray[i] == ext) 
    { 
     allowSubmit = true; break; 
    }
  }
 } 


 if (allowSubmit)
 {
  form.submit();
 }
 else
 {
  alert("Please only submit files that end in:  "
+ (extArray.join("  ")) + "\nPlease select a new "
+ "file and try again. Thank you.");
 }
}
</script>

I've deliberately put the curly braces on seperate lines for visual clarity. Don't know if any of this is the culprit but at least now you can easily where a function/routine starts and stops.

There's always a better way. The fun is trying to find it!
 
Hi... thank you for fixing the way it looked... it looks much much better than what it was.... I tried to use your code and it still doesn't work on netscape on PCs. I don't know why this is happening... any help with this will be greatly appreciated.

Thanks all...
A.
 
Can you post the html code or post a link to the page?

There's always a better way. The fun is trying to find it!
 
Here is the whole HTML page...

Code:
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%><%
// *** Restrict Access To Page: Grant or deny access to this page
var MM_authorizedUsers="";
var MM_authFailedURL="sorryauthor.asp";
var MM_grantAccess=false;
if (String(Session("MM_Username")) != "undefined") {
  if (true || (String(Session("MM_UserAuthorization"))=="") || (MM_authorizedUsers.indexOf(String(Session("MM_UserAuthorization"))) >=0)) {
    MM_grantAccess = true;
  }
}
if (!MM_grantAccess) {
  var MM_qsChar = "?";
  if (MM_authFailedURL.indexOf("?") >= 0) MM_qsChar = "&";
  var MM_referrer = Request.ServerVariables("URL");
  if (String(Request.QueryString()).length > 0) MM_referrer = MM_referrer + "?" + String(Request.QueryString());
  MM_authFailedURL = MM_authFailedURL + MM_qsChar + "accessdenied=" + Server.URLEncode(MM_referrer);
  Response.Redirect(MM_authFailedURL);
}
%>
<!--#include file="Connections/author.asp" -->
<%
var rsName__MMColParam = "1";
if (String(Session("MM_Username")) != "undefined" && 
    String(Session("MM_Username")) != "") { 
  rsName__MMColParam = String(Session("MM_Username"));
}
%>
<%
var rsName = Server.CreateObject("ADODB.Recordset");
rsName.ActiveConnection = MM_author_STRING;
rsName.Source = "SELECT * FROM authors WHERE authUsername = '"+ rsName__MMColParam.replace(/'/g, "''") + "'";
rsName.CursorType = 0;
rsName.CursorLocation = 2;
rsName.LockType = 1;
rsName.Open();
var rsName_numRows = 0;
%>
<html>
<head>

<script language="javascript">

function fun ()
{ 
 var path = document.upform.blob.value;
 var pattern = /\s/;
 file = path.split("\\");
 file.reverse();
 if (pattern.test(file[0])) {
     alert ("Your filename includes spaces. Please rename your file per the guidelines on this page and try again.");
 }
 else if (document.upform.docName.value.length == 0)
 {
   alert("Please enter the Paper Title");
 }
 else
 {
 LimitAttach(this.upform, this.upform.blob.value);
 } //{document.upform.submit();}
    
}

extArray = new Array(".htm", ".html", ".pdf", ".doc");

function LimitAttach(form, file) 
{
 allowSubmit = false;
 if (!file)
 {
 return;
  }

 while (file.indexOf("\\") != -1)
 {
  file = file.slice(file.indexOf("\\") + 1);
  ext = file.slice(file.indexOf(".")).toLowerCase();
  for (var i = 0; i < extArray.length; i++) 
  {
    if (extArray[i] == ext) 
    { 
     allowSubmit = true; break; 
    }
  }
 } 


 if (allowSubmit)
 {
  form.submit();
 }
 else
 {
  alert("Please only submit files that end in:  "
+ (extArray.join("  ")) + "\nPlease select a new "
+ "file and try again. Thank you.");
 }
}
</script>

</script>

<title>ISPR | Paper Submission Page</title>
<link rel="stylesheet" href="../../style.css" type="text/css">
</head>

<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1">
  <tr>
    <td width="100%">&nbsp;</td>
  </tr>
</table>

<table width="640" border="0" align="center" bgcolor="#CCCCCC">
  <tr>
    <td><div align="center"><font size="4" face="Arial, Helvetica, sans-serif">
      ISPR
      PAPER SUBMISSION PAGE</font></div></td>
  </tr>
</table>

<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1">
  <tr>
    <td width="100%">
    <p align="center">&nbsp;<br>
    NOTE: This page works <b>best with Microsoft Internet Explorer 5.x </b>or higher 
    and with javascript enabled<br>
    (to enable javascript in IE, select the menu options &quot;Tools,&quot; then &quot;Internet 
    Options...,&quot; then click<br>
    on the &quot;Advanced&quot; tab and check the appropriate option box).<br>
&nbsp;</td>
  </tr>
</table>

 <center>
        <TABLE ALIGN="CENTER style=" WIDTH="789" style="border-
collapse: collapse; border-collapse:collapse" bordercolor="#111111" cellpadding="5">
          <TR> 
            <TD colspan="2" width="785">
        <font face="Arial,Helvetica">
        <p><b><font face="Arial, Helvetica, sans-serif"> Please use the form and 
          follow the guidelines below to submit your paper. </font>
        </b>
        <p><font face="Arial, Helvetica, sans-serif"> <b>If you have any problems, 
          please send an e-mail message to </b> <a href="mailto:help@ispr.info">
        <b>help@ispr.info</b></a><b>.</b></font><p> <font face="Arial, Helvetica, sans-serif"><u>
            Guidelines</u></font></font><ul>
        <li type="square"><Font face="Arial, Helvetica, sans-serif" size="2">Your 
          file must be in hypertext markup language (.html), MS Word (.doc) or 
        Acrobat Reader (.pdf) format. <br>
&nbsp;</font></li>
        <li type="square"><Font face="Arial, Helvetica, sans-serif" size="2">
        .html files cannot contain embedded files of any kind (including 
        graphics, images, etc.). <br>
&nbsp;</font></li>
        <li type="square"><Font face="Arial, Helvetica, sans-serif" size="2">The 
        maximum file size is 2 megabytes.<br>
          &nbsp;</font></li>
        <li type="square"><Font face="Arial, Helvetica, sans-serif" size="2">Do 
          not include your name or any contact information anywhere in your 
        .html, .doc 
          or .pdf file.</font><font face="Arial, Helvetica, sans-serif"> <br>
          &nbsp;</font></li>
        <li type="square"><Font face="Arial, Helvetica, sans-serif" size="2">Do 
          not include your name anywhere in the name of your file.<br>
          &nbsp;</font></li>
        <li type="square"><Font face="Arial, Helvetica, sans-serif" size="2"> 
          <u>Do not include spaces</u> in the name of your file. Replace spaces with the 
          underscore character (e.g., <i>file_name.html</i></font><font face="Arial, Helvetica, sans-serif"><i><Font size="2">).<br>
&nbsp;</font></i></font></li>
        <li type="square">Be sure to fill in all of the fields below.</li>
            </ul>
            <p>
          <font size="2" face="Arial, Helvetica, sans-serif">To submit your 
          paper, fill in your registered User Name and the title of your paper in 
          the form below. Then click the Browse button to locate the file that 
          contains your paper on 
          your computer.&nbsp;Once you have located and selected the file, click the 
          Submit button.</font><p>
          &nbsp;</td>
          </tr>
		  
		    <FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="outputFile.asp" name="upform">
          
		  <TR align="left" valign="top"> 
            
        <TD width="290"><Font face="Arial" size="2"><b><font color="#008888">
        Your User Name</font></b> <br>
        <font color="#008888">(This is the name with which you registered and 
        logged into this system)<br>
&nbsp;</font></font></td>
            <TD width="491"> 
              <INPUT NAME="authUsername" id="authUsername" value="<%=(rsName.Fields.Item("authUsername").Value)%>" 
size="20" maxlength="255"></td>
          </tr>
          <TR align="left" valign="top">
            <TD width="290"><b>
            <font face="Arial, Helvetica, sans-serif" color="#008888">Paper</font></b><font color="#008888" size="2" face="Arial, Helvetica, sans-serif"><b> 
            Title</b><br>
            (This is the full title of the paper you are submitting; it can be 
            as long as 60 characters and can contain spaces between the words.
            <i>Do not leave this blank</i>!)<br>
&nbsp;</font></td>
            <TD width="491">
            <input name="docName" type="text" id="docName" size="46"> </td>
          </tr>
          <TR align="left" valign="top"> 
            <TD width="290"><Font face="Arial" size="2" color="#008888"><b>File Name</b><br>
            (This is the name of the file on your computer that contains your 
            paper; it must not contain spaces and it must end in <i>.html</i>,
            <i>.doc</i>, or <i>.pdf</i>) <br>
&nbsp;</font></td>
            <TD width="491"> 
              <INPUT TYPE="file" NAME="blob" size="20">
            </td>
          </tr>
          <TR> 
            <TD width="290"></td>
            <TD width="491"></td>
          </tr>
          <TR> 
            <TD colspan="2" width="785"> 
              <p align="center"> 
                <input type="button" value="Submit" name="Enter" onClick="fun()" style="font-weight: bold">            
            </td>
          </tr>
		  </FORM>
        </TABLE>
		
</center>
<p align="center">&nbsp;</p>
</html>
<%
rsName.Close();
%>

Thanks a lot...

A.
 
Two things - make sure you've defined your input tags correctly: <input type="[text,file,submit,reset,button]" name="[whatever]" size="[not mandatory but...]" value="[not mandatory]">

Then - change this: LimitAttach(this.upform, this.upform.blob.value);

to this: LimitAttach(document.upform, document.upform.blob.value);

You never passed the form to your function so it doesn't know what "this" means.

Another way to call your function would be to use the onsubmit call in your form statement, rather than using the onclick event:
<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="outputFile.asp" name="upform" onsubmit="fun(this)">




There's always a better way. The fun is trying to find it!
 
Hi I tried what you suggested... still no change when I try it with Netscape... when I used onsubmit instead of onclick it doesn't work on IE. So from just Netscape.. it became both IE and Netscape... very wierd... thanks for all the help...

A.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top