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

Cancelling a form POST action 1

Status
Not open for further replies.

trimtrom

Programmer
Dec 12, 2003
35
0
0
GB
Hello

I am a web beginner, and I am trying to write a site which involves an opening login page. There is a form as follows:

<form name="frontform" method=POST action="<label>Username </label><input name="Userniame"><br><br><br>
<label>Password </label><input name="Passwiord"><br><br><br>
</fieldset><br>
<button name="pjtbtn" type=submit>Submit</button>
</form>

I am trying to get the user to fill in the correct details that will then get POSTed to the next page. I have done validation as follows:

<script language=vbscript>
sub pjtbtn_onclick
if len(trim(document.frontform.Userniame.value))=0 then
msgbox "Please enter username"
end if
if len(trim(document.frontform.Passwiord.value))=0 then
msgbox "Please enter password"
end if

end sub
</script>

What I need now is a method of cancelling the POST if the user does not fill in the details, and returning him to the form so he can try again. I presume this will take place in the script section: am I correct?

I have chosen to use VBscript not Javascript as all this takes place on an intranet where we know we will be using only IE.

I would be grateful for code snippets showing me a method of cancelling the POST unless the input is validated correctly.

Many thanks,

Trimtrom
 
[1]
>[tt]<button name="pjtbtn" type=submit>Submit</button>[/tt]
[tt]<[red]input[/red] name="pjtbtn" type=[blue]"[/blue]submit[blue]"[/blue]>Submit</[red]input[/red]>[/tt]
[2]
>[tt]sub pjtbtn_onclick[/tt]
[tt]sub [red]frontform_onsubmit[/red][/tt]
[3][tt]
sub frontform_onsubmit
if len(trim(document.frontform.Userniame.value))=0 then
msgbox "Please enter username"
[red]window.event.returnvalue=false[/red]
[blue]exit sub[/blue]
end if
if len(trim(document.frontform.Passwiord.value))=0 then
msgbox "Please enter password"
[red]window.event.returnvalue=false[/red]
[blue]exit sub[/blue]
end if

end sub
[/tt]
 
Also to improve the input tags.
[4]
>[tt]<input name="Userniame">[/tt]
[tt]<input [blue]type="text"[/blue] name="Userniame">[/tt]
>[tt]<input name="Passwiord">[/tt]
[tt]<input [red]type="password"[/red] name="Passwiord">[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top