Jump to content

errors using document.getElementById('salespageform').elements;


Guest Dennis 4D
 Share

Recommended Posts

Guest Dennis 4D

I need to validate some fields on a form. I have cut the script down to bare minimum to try to isolate the errors but no luck. This is the script

function verifyimages(){	var errorstatus = "groovey";	var errormsg = "";	var str = '';  	var elem = document.getElementById('salespageform').elements;  	for(var i = 0; i < elem.length; i++) {			document.write("file type: " + elem[i].type + " <br>" );		document.write(" value: " + elem[i].value + " <br>");		 }  				if (errorstatus=="groovey"){			document.salespageform.submit();			return true;		} else {			alert(errormsg+"\n You can only upload a gif, jpg, jpeg or prn image");			return false;		}}

The form that calls this code has about 30 fields some text, some file, some hidden. When I replace the section that say

document.write("file type: " + elem[i].type + " <br>" );		document.write(" value: " + elem[i].value + " <br>");

with this

for(var i = 0; i < elem.length; i++) { 		 str += "<b>Type:</b>" + elem[i].type + "  ";  		 str += "<b>Name:</b>" + elem[i].name + "  "; 		 str += "<b>Value:</b><i>" + elem[i].value + "</i>  ";  		 str += "<BR>"; 		 		 }  		document.write(str);

it works fine.But what I really want to do ischeck that if the file type is "file" that the value is a jpeg, prn or gif.I know how to do that with regular expressions but I am getting errors -- different ones in IE and Firebox.So the first code presented throws this error in IEIt displays the first file type and then errors with the message PERMISSION DENIEDI also tried the following code in the for loop

for(var i = 0; i < elem.length; i++) { 		if (elem[i].type  == "file"){														document.write('its a file');						  }}

that throws the error message that document.salespageform.submitis undefinedthese "seem" to work in firefoxAny help is appreciated

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...