lonewolf217 Posted June 18, 2008 Share Posted June 18, 2008 I have tried searching both these forums and google and while there are a few examples of how to use an onSubmit event I am still a little confused. This is the next step for me after learning my asp and php this week for a project, now I want to validate the html forms that I am using. I do know that I need to add a line like this <form name="myform" method="post" action="add.asp" onSubmit="return myform_OnSubmit()"> questions: 1) this function myform_OnSubmit(), does this belong in the same file as the forms, or should it be on the action page? 2) if it belongs in the same file, and the submit function I am using is in vbscript, does my page have to be .asp instead of .html or can I use <SCRIPT LANGUAGE="VBScript"> on an HTML page? 3) if it belongs in the same file, what section does it go in ? will it go before the <html> section, in the <head> or in the <body> ? Sorry if these questions are basic, I have done very little with forms and zero with form validation before so the concept is still very new to me. I have gotten some help from google but I am still missing that one piece of information that will bring it all together Quote Link to comment Share on other sites More sharing options...
haku Posted June 18, 2008 Share Posted June 18, 2008 1) It should be on the same page as the form, or in an external file linked to on the same page as the form. If it is not on that page or in an external file downloaded to that page, it won't be accessible by that page. 2) First lets look at what .asp and .html are. (X)HTML is a language that browsers read in, interpret, and display according to the rules of that browser. A site doesn't actually exist, rather it's just bunch of code. Each browser interprets that code in its own way, which is why sites look different in different browsers. For the most part, browsers require (X)HTML in order to be able to show a formatted site (there are some exceptions like XML, but they are not in common use). ASP is a programming language that takes in input (user input, time of day, page information, server information etc) and outputs text, almost always in the form of (X)HTML. The (X)HTML that the ASP outputs is what is used by the browser to display the site. So to answer your question, you passing HTML (or XHMTL) to the browser whether your page's file extension is .asp or .html. So you can use the script tag on either of them. If your page is .asp, you just output the script tag using asp. 3) Traditionally, script tags were included in the head section of the site, and still are on most sites. Either that or somewhere on the page above where the script was called. However as scripting practices change, they are often included at the end of the page right before the body tag, as this speeds up the visual component of the page download by waiting to download the javascript until after everything else on the page has loaded. But at the level you are at, you may find that your scripts don't work if you put them here, so for the time being, I would suggest you put them in the head of your document. As a final point, javascript and/or vbasic validation is good as an extra on your site, but you should not depend on it for your form validation, as users can turn it off, thereby bypassing it altogether. You should always do the validation server-side (using ASP, PHP or any other server-side language), and then add javascript/vbasic validation over top to increase functionality. Quote Link to comment Share on other sites More sharing options...
lonewolf217 Posted June 18, 2008 Author Share Posted June 18, 2008 I think for now I will go the simpler approach of just redirecting to a confirm.asp page which will validate all of the forms. Ideally i would have liked to remain on the same page to validate but it might be a little difficult for me right now On a side note, this is a very small private site for me and a couple other people in my department just for a place to store some information, so no fancy protection or scripting is really necessary. the whole project was really an excuse to learn it for myself while doing it on work time Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted June 23, 2008 Share Posted June 23, 2008 The better thing to do is make the submit button a type=button and then execute the js onclick. then after all things are correct(after checking w/ js), then do "this.form.submit();" to send it thru. If I remember correctly, if you do onsubmit, it will submit the data whether its correct or not Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.