...

View Full Version : Javascript Validation with a twist



THOMSKINT
03-17-2005, 02:42 PM
Hi,

I have a form with 2 submit buttons with seperate actions one sends the form and the other uploads a file. I'm having a problem with users browsing for a file and clicking the wrong button. So i need to check to see if the attachment field has anything in it if the users clicks the wrong button and warn them that they have not uploaded their file and offer a prompt with text and a continue and cancel button. Any ideas?

My code so far is:

<script language="JavaScript">

<!--

function validate_filefield ( )
{
valid = true;

if (myform.attachment.value.length > 0 )

{
return confirm('Warning you have not clicked the upload filebutton');
valid = true;
}
return valid;
}

//-->

</script>


<form name="myform" method="post" action="gohere.cfm">


<Input type=file name=attachment class="formfield" class="button">
<input type=submit value="Upload File" name=attach onClick="this.form.action='sendfaxdocument.cfm';" class="button">
<input type="submit" name="send" value="Send Details" onclick="this.form.action='job3.cfm'; return validate_filefield ();"></p>

</form>

codegoboom
03-17-2005, 02:49 PM
How about disable-ing the one button until the onchange event takes place for the file input?

THOMSKINT
03-17-2005, 03:03 PM
Unfortunately I have to have the option for users to continue or upload a file I just need to warn them.

codegoboom
03-17-2005, 03:06 PM
The cofirm() method should work... there are many examples of that around here, btw.

THOMSKINT
03-17-2005, 09:16 PM
Yep got it to work,

thanks for the tips :)

hemebond
03-17-2005, 10:22 PM
What if they have Javascript disabled? What does your form do then? Why not seperate the form into two. It makes a lot more sense, simplifies processing, and is safer.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum