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

Form Validation on the fly - onBlur()

Status
Not open for further replies.

Gatchaman

Programmer
Jan 21, 2003
71
AU
Hey all, a bit of background:

I have a website that uses 1 standard template thingy, a .html file, then this is used to display the rest of the site within it, which is .asp

My problem is, since I'm using this template, I cannot put anything in the <head> section, ie. scripts. This hasn't been a problem yet, but now I'm wanting to validate a form before it is submitted, so I was wondering if there is anyway I can use the onBlur function and check the value in the form.

eg.

Code:
<input type='text' name='someName' id='someName' onBlur='validate someName here'>

Just wondering if that is possible, thanks in advance for any help.

Damon
 
Well, yes it is. However, you dont always have to put the javascript in the header. You can put your <script></script> tags anywhere in the body as well. I would suggest that you put your scripting in the body and leave the onblur handler as simple as possible, as this makes debuggin much easier.
&quot;Why is it always the quiet ones?&quot;

Robert Carpenter
questions? comments? thanks? email me!
linkemapx@hotmail.com
AIM & MSN: robacarp
 
You can even add an external javascript validation function to your HTML template this way :
1) In your HTML template, give an id attribute to your head tag like that :
Code:
<Head id=&quot;HeadTag&quot;>[Code]
2) For each asp content, define a .js (or a .vbs) file that'll content your validation function. To ease maintenance, you can call je Js file the same name than the asp file (ie: &quot;Cart.js&quot; for &quot;Cart.asp&quot;)
3) Add this function in the HTML template head :
[code]<Script language=&quot;JavaScript&quot;>
function AddScript(ScriptName) {
  var objTmpTag = document.getElementById(&quot;HeadTag&quot;);
  var objNewTag = document.createElement(&quot;SCRIPT&quot;);
  objNewTag.Language = &quot;JavaScript&quot;; //or VBscript depending on the language you chose
  objNewTag.type= &quot;text/vbscript&quot;;
  objNewTag.src = ScriptName;
  objTmpTag.appendChild(objNewTag);
}
</script>
4 ) in all ASP, add an event handler on the &quot;onload&quot; event of any tag this way :
Code:
<Div onload='AddScript(&quot;cart.js&quot;);'>

This way, you dynamically linked on page loading a new external script file to the HTML. All functions contained in the js file are now aviable for calling on click, mosemove or any other event.
Water is not bad as long as it stays out human body ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top