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!

IF statement - i think !? 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi everyone,

May i ask a question.... i am completely new to vbscript.

I have a form in html code and on this form i have boxes for people to input information. Once the info has been input, the info is then processed through an ASP page (which writes the info to a mdb database and also emails me with the info)... i had help with the html form and asp page.

My problem is this.....

If the user does not enter information, then i get an asp line error code appear......

My solution ideally would be this......

If a user does not enter information, i would like a message pop up to say " you must enter information in ALL fields"

Please can anyone help me with this?..... someone mentioned to me that i would need to use an IF statement. I dont know anything about IF statements !!!!

Please help !
 
You can do this :
Code:
<SCRIPT language=&quot;JavaScript&quot;>

function soumettre() {
	if ((window.document.saisie.field1.value == &quot;&quot;) || 	    (window.document.saisie.field2.value == &quot;&quot;) ||
            (window.document.saisie.field3.value == 0) )
	{
		alert(&quot;fill all the fields.&quot;);
		event.returnValue=false;
	}else{
		window.document.saisie.submit();
		event.returnValue=false;
	}
}

</SCRIPT>
and then :
Code:
<Form name=&quot;saisie&quot; id=&quot;saisie&quot; action=&quot;test.asp&quot; method=&quot;post&quot;>
<input type=&quot;text&quot; name=&quot;field1&quot;>
<input type=&quot;text&quot; name=&quot;field2&quot;>
<input type=&quot;text&quot; name=&quot;field3&quot;>
<input type=&quot;button&quot; value=&quot;submit&quot; onclick=&quot;soumettre();&quot;>
Water is not bad as soon as it stays out human body ;-)
 
many thanks.... but i am using vbscript

could i use javascript ?

What would be the code for Vbscript.... i would rather stick with vbscript if i can ???!!!

Thanks very much for your reply [pipe]
 
Code:
<SCRIPT language=&quot;VbScript&quot;>

sub soumettre() 
    if window.document.saisie.field1.value = &quot;&quot; OR
       window.document.saisie.field2.value = &quot;&quot; OR
       window.document.saisie.field3.value = 0 Then
        msgbox &quot;fill all the fields.&quot;
        event.returnValue=false
    else
        window.document.saisie.submit()
        event.returnValue=false
    end if
end function

</SCRIPT>
and then :
Code:
<Form name=&quot;saisie&quot; id=&quot;saisie&quot; action=&quot;test.asp&quot; method=&quot;post&quot;>
<input type=&quot;text&quot; name=&quot;field1&quot;>
<input type=&quot;text&quot; name=&quot;field2&quot;>
<input type=&quot;text&quot; name=&quot;field3&quot;>
<input type=&quot;button&quot; value=&quot;submit&quot; onclick=&quot;call soumettre()&quot;>
Water is not bad as soon as it stays out human body ;-)
 
Hi ..... its me again !!!

I wonder if i can bother you again?

I am after a HUGE favour here..... would you be kind enough to alter the vbscript that you did for me but this time (compared to the CODE i have included) .... fill in the bits that i need for my particular code....ie: change the saisie, field and soumettre things for me and put in place what i need for my form in particular??.... please ?!!!

I will buy you a beer sometime !!! [thumbsup2]



<HTML>
<ALIGN=&quot;left&quot;><FONT COLOR=#000000><FONT SIZE=&quot;+2&quot;>Module 2</B></FONT><p/>
<HEAD>
<TITLE>ECDL HELP PAGES</TITLE>


</HEAD>
<CENTER>
<BODY BACKGROUND=&quot;&quot; BGCOLOR=&quot;#ffffff&quot; TEXT=&quot;#000000&quot; LINK=&quot;#0000ff&quot; VLINK=&quot;#800080&quot; ALINK=&quot;#ff0000&quot;>

<FORM ACTION=&quot;managing_files.asp&quot; METHOD=&quot;POST&quot;>

<WIDTH=&quot;100%&quot;>
<TR>
<TH><B><FONT COLOR=#0000ff><FONT SIZE=&quot;+5&quot;>Using a Computer and Managing Files<CENTER></FONT></FONT></B></TH><p/>
<TH><IMG SRC=&quot;euro.gif&quot; ALIGN=&quot;TOP&quot; ALIGN=&quot;CENTRE&quot; HSPACE=400 VSPACE=0><CENTER></TH>
</TR>
</TABLE WIDTH=&quot;100%&quot;><p/>
<FONT COLOR=#ff0000><B>Please enter your details</B></FONT><p/>
Name: <INPUT TYPE=&quot;text&quot; NAME=&quot;name&quot; SIZE=&quot;40&quot; MAXLENGTH=&quot;50&quot; VALUE=&quot;&quot;><p/>
Dept:   <INPUT TYPE=&quot;text&quot; NAME=&quot;dept&quot; SIZE=&quot;40&quot; MAXLENGTH=&quot;50&quot; VALUE=&quot;&quot;><p/>
Ext:     <INPUT TYPE=&quot;text&quot; NAME=&quot;ext&quot; SIZE=&quot;10&quot; MAXLENGTH=&quot;20&quot; VALUE=&quot;&quot;><p/>
<FONT COLOR=#0000ff><FONT COLOR=#ff0000><B>Please tick a box that represents the nature of your question</B></FONT></FONT><p/>



</BODY>Operating System                 <INPUT TYPE=&quot;checkbox&quot; NAME=&quot;operatingsystem&quot; VALUE=&quot;1&quot;><p/>

<p/>
Desktop                               <INPUT TYPE=&quot;checkbox&quot; NAME=&quot;desktop&quot; VALUE=&quot;1&quot;><p/>
File Management                  <INPUT TYPE=&quot;checkbox&quot; NAME=&quot;filemanagement&quot; VALUE=&quot;1&quot;><p/>
Search/Edit                          <INPUT TYPE=&quot;checkbox&quot; NAME=&quot;searchedit&quot; VALUE=&quot;1&quot;><p/>
Printing                                <INPUT TYPE=&quot;checkbox&quot; NAME=&quot;printing&quot; VALUE=&quot;1&quot;><p/>
None of the above               <INPUT TYPE=&quot;checkbox&quot; NAME=&quot;noneoftheabove&quot; VALUE=&quot;1&quot;><p/>


<FONT COLOR=#ff0000><B>Please enter your question in the box below:</B></FONT><p/>

<TEXTAREA NAME=&quot;question&quot; ROWS=&quot;5&quot; COLS=&quot;60&quot;></TEXTAREA><p/>





<form action=&quot;managing_files.asp&quot; method=&quot;post&quot;><p/><INPUT TYPE=&quot;submit&quot; VALUE=&quot;Submit your question&quot;>
</form><p/>
<p/>
<B><FONT COLOR=#0000ff>An ECDL Tutor will reply within 48hours.</FONT></B><p/>
<I>Thank you for your question.</I>









</HTML>






</body>
</html>
 
Ain't you a HUGE lazy boy ? ;-)
Ok i'll do it for you but got no time today. wait till tomorow.

PS : is it normal that you have 2 closing tags for your html tag and that your closing body tag is after the first </html> tag ???
I think the first </HTML> is an error (may be a &quot;wild&quot; cut and paste ?) Water is not bad as soon as it stays out human body ;-)
 
LOL - yes you might be right about the lazy thing... but i have been given this by a colleague thats too lazy to do themselves !!!!........ and also cant be bothered to work out how it all works !! ( a bit like myself) !!!.... actually, i would love to know a lot more about HTML, ASP and VBScript..... but the NHS is bad for sending their staff on courses........

Your also probably right about the HTML tags..... but thanks for pointing that out... an oversight on my part.... trying to rush things and perhaps a bit of a cut and paste job too !!!

I look forward to checking the forum tomorrow [dazed]

alternatively..... would you like my email address?

Thanks once again
David
 
no offense to all but both need a little help.
Targol, your msgbox function needed help, you had a sub ending with a end function and a view other slight changes.

david pook, you do not want to use vbscript for this type of validation but I'll humor you anyways. Also you need some serious help with your codiong conventions no matter who or where this came from. the extra tags and the mess of code etc..


<html>
<head>
<TITLE>ECDL HELP PAGES</TITLE>
<SCRIPT language=&quot;VbScript&quot;>
sub soumettre()
if document.frm.name.value = &quot;&quot; OR document.frm.dept.value = &quot;&quot; OR document.frm.ext.value = &quot;&quot; Then
Var = msgbox(&quot;fill all the fields.&quot;,0)
Exit Sub
frm.focus
else
document.frm.submit()

end if
end sub
</SCRIPT>
</HEAD>
<BODY BACKGROUND=&quot;&quot; BGCOLOR=&quot;#ffffff&quot; TEXT=&quot;#000000&quot; LINK=&quot;#0000ff&quot; VLINK=&quot;#800080&quot; ALINK=&quot;#ff0000&quot;>
<ALIGN=&quot;left&quot;><FONT COLOR=#000000><FONT SIZE=&quot;+2&quot;>Module 2</B></FONT><p/>
<CENTER>
<FORM ACTION=&quot;managing_files.asp&quot; METHOD=&quot;POST&quot; NAME=&quot;frm&quot;>

<WIDTH=&quot;100%&quot;>
<TR>
<TH><B><FONT COLOR=#0000ff><FONT SIZE=&quot;+5&quot;>Using a Computer and Managing Files<CENTER></FONT></FONT></B></TH><p/>
<TH><IMG SRC=&quot;euro.gif&quot; ALIGN=&quot;TOP&quot; ALIGN=&quot;CENTRE&quot; HSPACE=400 VSPACE=0><CENTER></TH>
</TR>
</TABLE WIDTH=&quot;100%&quot;><p/>
<FONT COLOR=#ff0000><B>Please enter your details</B></FONT><p/>
Name:
<INPUT TYPE=&quot;text&quot; NAME=&quot;name&quot; SIZE=&quot;40&quot; MAXLENGTH=&quot;50&quot; VALUE=&quot;&quot;><p/>
Dept:
<INPUT TYPE=&quot;text&quot; NAME=&quot;dept&quot; SIZE=&quot;40&quot; MAXLENGTH=&quot;50&quot; VALUE=&quot;&quot;><p/>
Ext:
<INPUT TYPE=&quot;text&quot; NAME=&quot;ext&quot; SIZE=&quot;10&quot; MAXLENGTH=&quot;20&quot; VALUE=&quot;&quot;><p/>
<FONT COLOR=#0000ff><FONT COLOR=#ff0000><B>Please tick a box that represents the nature of your question</B></FONT></FONT><p/>
Operating System
<INPUT TYPE=&quot;checkbox&quot; NAME=&quot;operatingsystem&quot; VALUE=&quot;1&quot;><p/>
<p/>
Desktop
<INPUT TYPE=&quot;checkbox&quot; NAME=&quot;desktop&quot; VALUE=&quot;1&quot;><p/>
File Management
<INPUT TYPE=&quot;checkbox&quot; NAME=&quot;filemanagement&quot; VALUE=&quot;1&quot;><p/>
Search/Edit
<INPUT TYPE=&quot;checkbox&quot; NAME=&quot;searchedit&quot; VALUE=&quot;1&quot;><p/>
Printing
<INPUT TYPE=&quot;checkbox&quot; NAME=&quot;printing&quot; VALUE=&quot;1&quot;><p/>
None of the above
<INPUT TYPE=&quot;checkbox&quot; NAME=&quot;noneoftheabove&quot; VALUE=&quot;1&quot;><p/>
<FONT COLOR=#ff0000><B>
Please enter your question in the box below:</B></FONT><p/>
<TEXTAREA NAME=&quot;question&quot; ROWS=&quot;5&quot; COLS=&quot;60&quot;></TEXTAREA><p/>
<p/>
<INPUT TYPE=&quot;Button&quot; VALUE=&quot;Submit your question&quot; onclick=&quot;call soumettre()&quot;>
</form><p/>
<p/>
<B><FONT COLOR=#0000ff>An ECDL Tutor will reply within 48hours.</FONT></B><p/>
<I>Thank you for your question.</I>
</body>
</html>

you will need a further validation step for the checkbox's. works differently then just &quot;&quot; if you need that you can check in a search anywhere for vbscript check box validation recommend javascript though.

I have done nothing but modify the above code provided, and have not tested it. IF you have issues with my rewrite let me know
admin@onpntwebdesigns.com
 
Well, without wanting to be cruel, let me tell you that your html code is ... well how can i say ... exotic :-D.
Please, before cuting and pasting the correct code that i'll post you soon, read these :

In general
- Html tags are almost all blocks tags that means that they need an openning tag (ie :
Code:
<BODY>
) and a closing tag (ie :
Code:
</BODY>
).
- Openning and Closing tags from two blocks MUST NOT interfer. ie:
Code:
<TABLE>...<CENTER>...</TABLE>...</CENTER>
is wrong while
Code:
<TABLE>...<CENTER>...</CENTER>...</TABLE>
is good.
- The only tags that don't need openning and closing (if I don't forget anything) are :
Code:
<IMG>, <BR>, <INPUT>
for the most common ones.
- If you want to comply with latest W3C suggests, end all the tags that doesn't want closing tag by &quot;/>&quot; rather than by &quot;>&quot; only. (ie : prefer
Code:
<BR/>
than
Code:
<BR>
)

In details
-
Code:
<WIDTH=&quot;100%&quot;>
: no Width tag exist in HTML, width is an attribute for other tags (ie :
Code:
<TABLE width=&quot;100%&quot;>
)
-
Code:
<TR>
tag meens &quot;Table Row&quot; so can exist only between
Code:
<TABLE>
and
Code:
</TABLE>
tags.
- Same remark for
Code:
<TH>
that means &quot;Table Header&quot;
-
Code:
<FONT COLOR=#0000ff><FONT SIZE=&quot;+5&quot;>
can be replaced by
Code:
<FONT COLOR=#0000ff SIZE=&quot;+5&quot;>
-
Code:
<P>
tag (for Paragraph) needs an openning and a closing tag. If you just want a carriage return, don't use
Code:
<P/>
(that is wrong), put the
Code:
<BR/>
tag.
- Your button can be placed in the same form than all the others inputs.

I'm almost sure that you use MSIE to test your page : it accept more HTML than Netscape. I think that if you try to open the page whose code you send in a Netscape Browser, you'll have big surprises !!! Water is not bad as soon as it stays out human body ;-)
 
Her's your page after a few mods :
- I changed the checkboxes to radio because i thought that just one could be choosen.
- I put the script in Javascript too because of compatibility reasons (into comments).

Code:
<HTML>
<HEAD>
<TITLE>ECDL HELP PAGES</TITLE>
<SCRIPT language=&quot;JScript&quot;>
/*
function soumettre() {
var radioChecked;

    for (i=0; i<6; i++) {
	   if (window.document.saisie.QuestionNature[i].checked) {
	      radioChecked=window.document.saisie.QuestionNature[i].value;
		  break;
	   }
	}
    
    if (  window.document.saisie.usrname.value == &quot;&quot; 
       || window.document.saisie.dept.value == &quot;&quot;
       || window.document.saisie.ext.value == &quot;&quot;
       || window.document.saisie.question.value == &quot;&quot; ) {
        alert (&quot;You must fill all the fields and choose the QuestionNature of your question&quot;);
		return false;
    } else 
        window.document.saisie.submit();
}
*/
</SCRIPT>
<SCRIPT language=&quot;VBScript&quot;>

function soumettre() 
dim radioChecked

    for i=0 to 5
	   if window.document.saisie.QuestionNature(i).checked then
	      radioChecked=window.document.saisie.QuestionNature(i).value
	   end if
	next
'	msgbox &quot;radioChecked=&quot; & radioChecked
    
    if (  window.document.saisie.usrname.value = &quot;&quot; _ 
       OR window.document.saisie.dept.value = &quot;&quot; _
       OR window.document.saisie.ext.value = &quot;&quot; _
       OR window.document.saisie.question.value = &quot;&quot; ) then
        msgbox &quot;You must fill all the fields and choose the QuestionNature of your question&quot;
    else 
        window.document.saisie.submit()
	end if
end function

</SCRIPT>

</HEAD>
<BODY BACKGROUND=&quot;&quot; BGCOLOR=&quot;#ffffff&quot; TEXT=&quot;#000000&quot; LINK=&quot;#0000ff&quot; VLINK=&quot;#800080&quot; ALINK=&quot;#ff0000&quot; ALIGN=&quot;CENTER&quot;>
<P ALIGN=&quot;left&quot;><FONT COLOR=&quot;#000000&quot; SIZE=&quot;+2&quot;>Module 2</FONT></p>

<FORM NAME=&quot;saisie&quot; ACTION=&quot;managing_files.asp&quot; METHOD=&quot;POST&quot;>
<CENTER>
<B><FONT COLOR=&quot;#0000ff&quot; SIZE=&quot;+5&quot;>Using a Computer and Managing Files</FONT></B><BR/>
<IMG SRC=&quot;euro.gif&quot; ALIGN=&quot;TOP&quot; ALIGN=&quot;CENTRE&quot; HSPACE=&quot;400&quot; VSPACE=&quot;0&quot;/><BR/><BR/>
<FONT COLOR=#ff0000><B>Please enter your details</B></FONT><BR/>
Name: <INPUT TYPE=&quot;text&quot; NAME=&quot;usrname&quot; SIZE=&quot;40&quot; MAXLENGTH=&quot;50&quot; VALUE=&quot;&quot;><BR/>
Dept:   <INPUT TYPE=&quot;text&quot; NAME=&quot;dept&quot; SIZE=&quot;40&quot; MAXLENGTH=&quot;50&quot; VALUE=&quot;&quot;><BR/>
Ext:     <INPUT TYPE=&quot;text&quot; NAME=&quot;ext&quot; SIZE=&quot;10&quot; MAXLENGTH=&quot;20&quot; VALUE=&quot;&quot;><BR/>
<FONT COLOR=&quot;#ff0000&quot;><B>Please tick a box that represents the QuestionNature of your question</B></FONT><BR/>

Operating System                 <INPUT TYPE=&quot;radio&quot; NAME=&quot;QuestionNature&quot; value=&quot;operatingsystem&quot; ><BR/>
Desktop                          <INPUT TYPE=&quot;radio&quot; NAME=&quot;QuestionNature&quot; value=&quot;desktop&quot; ><BR/>
File Management                  <INPUT TYPE=&quot;radio&quot; NAME=&quot;QuestionNature&quot; value=&quot;filemanagement&quot;><BR/>
Search/Edit                      <INPUT TYPE=&quot;radio&quot; NAME=&quot;QuestionNature&quot; value=&quot;searchedit&quot; ><BR/>
Printing                         <INPUT TYPE=&quot;radio&quot; NAME=&quot;QuestionNature&quot; value=&quot;printing&quot; ><BR/>
None of the above                <INPUT TYPE=&quot;radio&quot; NAME=&quot;QuestionNature&quot; value=&quot;noneoftheabove&quot; checked=&quot;true&quot;><BR/>


<FONT COLOR=#ff0000><B>Please enter your question in the box below:</B></FONT><BR/>

<TEXTAREA NAME=&quot;question&quot; ROWS=&quot;5&quot; COLS=&quot;60&quot;>
<INPUT TYPE=&quot;button&quot; VALUE=&quot;Submit your question&quot; onclick=&quot;soumettre();&quot;>
</CENTER>
</form><BR/>
<BR/>
<CENTER>
<B><FONT COLOR=#0000ff>An ECDL Tutor will reply within 48hours.</FONT></B><BR/>
<I>Thank you for your question.</I>
</CENTER>
</BODY>
</HTML>


PS : if you want to pay me a beer :p, e-mail me to martin.hardy@ca-logitaine.fr when you come to Bordeaux (France).
Water is not bad as soon as it stays out human body ;-)
 
Thank you very much. What a GREAT help you have all been.

I can't believe the response i have had and i certainly will be using this forum again (dont groan) ! if i need any further help [pipe]

I havent checked the new code as yet but i will and am sure it will be exactly what i am looking for.

I cant stress enough, just how helpful you have all been and its wonderful.

Thanks again guys for your help
[medal][medal][medal][medal][medal][medal][medal][medal][medal][medal][medal][medal]
 
Targol,

You missed a closing tag:

<TEXTAREA NAME=&quot;question&quot; ROWS=&quot;5&quot; COLS=&quot;60&quot;></textarea>

Also, it might be a good idea to check for invalid entries as well as blank fields (ie spaces) in your validation code. As your code stands now, a form full of spaces could be submitted.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top