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

cannot get msgbox or alert to work 3

Status
Not open for further replies.

jcroft

Programmer
Aug 23, 2001
52
US
Am writing ASP,HTML pages how, can I get a message box or alert window to pop up is input box is empty...
 
Call a function on the onBlur event of the input box to validate the inupt (or with form onSubmit and validate entire form). Example:
Code:
<INPUT type='text' id='txtName' name='txtName' onBlur=&quot;CheckData('txtName');&quot;>

<SCRIPT language=JavaScript>
<!--
function CheckData(objName){
 var obj = document.all(objName);
 if(obj.length==0||obj.value==''){
   alert(objName + ' cannot be left blank');
  }
}
//-->
</SCRIPT>

 
if you are trying to open a msgbox in asp, users won't see it...since it is opening on the server..or something like that...either use a js alert or have code that is directly in your page (not in a msgbox) that does what you need to do.

mike
 
maybe this could be more easy to add to everry text box textarea...

<INPUT type=&quot;text&quot; id=&quot;txtName&quot; name=&quot;txtName&quot; onBlur=&quot;DoCheck(this);&quot;>

<textarea id=&quot;txtName1&quot; name=&quot;txtName1&quot; onBlur=&quot;DoCheck(this);&quot;></textarea>

<SCRIPT language=JavaScript>
function DoCheck(obj)
{
if(obj.value==&quot;&quot;)
{
alert('U have an empty field!');
obj.focus();
};
}
</SCRIPT>
________

George
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top