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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validation problems using an image

Status
Not open for further replies.

Miditen

Technical User
Jul 17, 2001
23
US
The following validation code works fine, however, I'd like to use an image as my submit button. When I change the button to: <INPUT TYPE=&quot;image&quot; SRC=&quot;images/pic.gif&quot;> the validation code still works, however, it doesn't stop the form from being submitted. I've tried a thousand variations including: Sub myForm_OnSubmit() without success. Any suggestions will be GREATLY appreciated.

<FORM ID=&quot;myForm&quot; METHOD=&quot;POST&quot; ACTION=&quot;somepage.asp&quot;>
<INPUT TYPE=&quot;text&quot; NAME=&quot;field1&quot; SIZE=&quot;30&quot;>
<INPUT TYPE=&quot;button&quot; NAME=&quot;myButton&quot;>
</FORM>

<SCRIPT LANGUAGE=&quot;vbscript&quot;>
Sub myButton_OnClick()
If Len (myForm.field1.value) = 0 Then
Alert &quot;Please enter a value.&quot;
myForm.field1.focus
Exit Sub
End If

Call myForm.submit()
End Sub
</SCRIPT>
 
The code works fine for me, i dont what's the problem... ________

George
 
Probably better to list the code as it is not working... When my submit type is &quot;button&quot; everything works fine. When my submit type is &quot;image&quot; the alert will still appear if the field is blank, however, once the user clicks OK on the alert, the form gets submitted without giving the user a chance to fix the blank field. Thanks!


<FORM ID=&quot;myForm&quot; METHOD=&quot;POST&quot; ACTION=&quot;somepage.asp&quot;>
<INPUT TYPE=&quot;text&quot; NAME=&quot;field1&quot; SIZE=&quot;30&quot;>
<INPUT TYPE=&quot;image&quot; SRC=&quot;somepic.gif&quot; NAME=&quot;myButton&quot;>
</FORM>

<SCRIPT LANGUAGE=&quot;vbscript&quot;>
Sub myButton_OnClick()
If Len (myForm.field1.value) = 0 Then
Alert &quot;Please enter a value.&quot;
myForm.field1.focus
Exit Sub
End If

Call myForm.submit()
End Sub
</SCRIPT>

 
somepic.gif isn't being viewed by another app while you're running this are you?
 
Nope. This form is the first and only place the image is viewed. I do need to make one correction - when an &quot;image&quot; type is used, the vbScript is ignored completely and the form is submitted, blank fields and all. Sorry for the misdirection.
 
I think I'd start by putting your script block within your <HEAD> tags instead of after your form tags. Then I'd put a message box as the first thing in your OnClick event code.

Oh, also, isn't Alert a JavaScript function or does this also work in VBScript? I always use the MsgBox function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top