SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast RandMan's Avatar
    Join Date
    Mar 2001
    Location
    Crossville, TN USA
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form input array validation

    The form contains 3 file input tags. The name for each is an array. This is for further processing by PHP script. I want to make sure at least one of the file input tags has selected a file.

    The rest of the validation script works, but I get a 'not object' error when I include the section that checks the file input tags. Would appreciate any help.

    Only relevant sections of code shown.
    Code:
    <script language="JavaScript" type="text/javascript">
    function checkform ( form ) {
    	var frm0 = document.form['uploadfile[0]'];
    	var frm1 = document.form['uploadfile[1]'];
    	var frm2 = document.form['uploadfile[2]'];
    	if ( frm0 == "" && frm1 == "" && frm2 == "" ) {
    		return false;
    	}
    	return true;
    }
    </script>
    
    <form enctype="multipart/form-data" action="upload.php" method="post" onsubmit="return checkform(this);">
    
    <input type="file" name="uploadfile[0]">
    <input type="file" name="uploadfile[1]">
    <input type="file" name="uploadfile[2]">
    
    </form>

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    function checkform ( f ) {
    	var frm0 = f.elements['uploadfile[0]'].value;
    	var frm1 = f.elements['uploadfile[1]'].value;
    	var frm2 = f.elements['uploadfile[2]'].value;
    	if ( frm0 == "" && frm1 == "" && frm2 == "" ) {
    		return false;
    	}
    	return true;
    }
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    SitePoint Enthusiast RandMan's Avatar
    Join Date
    Mar 2001
    Location
    Crossville, TN USA
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks beetle, that fixed it.

    Perhaps you can recommend a good book on Javascript.

  4. #4
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry - I've never purchased/used/read a javascript book.

    I always hear that Javascript: the Definitive Guide is good.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





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
  •