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

Stopping a submit action 2

Status
Not open for further replies.

Phailak

Programmer
Apr 10, 2001
142
CA
Hail,

I have a submit button which refers to a function in vbscript which is the following:

<SCRIPT LANGUAGE=&quot;VBScript&quot;>
Function Accept()
if document.frmtt.txtChrName.value = &quot;&quot; then
Alert(&quot;You have not entered a name?&quot;)
else
document.frmTT.action = &quot;SavingChr.asp?Player=<%=UID%>&HIT=<%=HIT%>&PAR=<%=PAR%>&DAM=<%=DAM%>&ARM=<%=ARM%>&LIF=<%=LIF%>&WIL=<%=WIL%>&CHA=<%=CHA%>&quot;
end if
end function
</SCRIPT>

So if the user has left the txtChrName field empty, I want to send a warning and NOT submit the document so in other words cancel the submit button's action.
Can this be done?

Phailak
 
That should do it.


<SCRIPT LANGUAGE=&quot;JavaScript&quot;><!--
function validate() {
if (document.myform.mytext.value > &quot;&quot;)
return true; // simple check for a value in the form field
else {
// prompt for alternative value
document.myform.mytext.value = prompt('Pleas include a value',document.myform.mytext.value);
setTimeout('document.myform.mybutton.click()',100);
return false;
}
}
//--></SCRIPT>

<FORM NAME=&quot;myform&quot; onSubmit=&quot;return validate()&quot;>
<INPUT TYPE=&quot;TEXT&quot; NAME=&quot;mytext&quot;>
<INPUT TYPE=&quot;SUBMIT&quot; NAME=&quot;mybutton&quot;>
</FORM>
 
Hail,

I'm sure it will work in Java, can anyone give it to me in VBscript?

Phailak
 
Just write the VBscript function to return true when you want it to submit and false if you don't want it to submit. Then call the method like normal from the onSubmit method of the form. There are other ways but this is easy enough.
Also I would like to point. As you may already know client-side VBscript is not a good choice if you are worried about Netscape compatibilty. There is a VBscript plugin for NS but I think like 2 people in the world have it. So basically anything you write in client-side VBscript will not work in NS.
Wushutwist
 
Hail,

Thanx for the specification and the advice. Actually, I'm aware of the limitations of vbscript, but I'm just in testing phase and I feel more comfortable with it. I know that eventually I'll have to change it to java.

Thanx again

Phailak
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top