what is supposed to do the button after validation? also, show the relevant HTML form code. without it, we can't help you nor should we doing guessing.
my mom is javascript, dad is javascripter, granpa is javascriptor, and my little sister is javasRidiculous. my nature language is javascript, then come spanish and english -- me
here is an example that verify if the field is empty, but you had not specified what is the type of the button (a submit or regular button) or what should happen after validation (submit the form or just nothing):
Code:
<form>
Type a user: <input type='text' name='user' />
<input type="button" onclick="if(!form.user.value.length)alert('User is empty');" />
</form>
my mom is javascript, dad is javascripter, granpa is javascriptor, and my little sister is javasRidiculous. my nature language is javascript, then come spanish and english -- me
consider that spaces count as valid. if not desired, then indicate what determine a valid field. that's, should only contain number, or alpha chars, or both, etc..
Last edited by ZeroKilled; 04-14-2009 at 07:24 PM.
my mom is javascript, dad is javascripter, granpa is javascriptor, and my little sister is javasRidiculous. my nature language is javascript, then come spanish and english -- me
every form's elements have a property named form which is a reference to the form object that contain such element. so, because the code is defined on a function (the event) that is attached to the element, i can use form property without knowing the name of the form or without even doing the long reference document.addTable. however, both way are valid. but always remember that the shortcut form can only be used within the element.
I don't have an alert!
i used it for example purpose, but if that is what you need, then ok.
So... this Javascript you are giving me executes BEFORE "addTable"
yes, it does. actually, event are like function declaration. so, you can place as many statement needed and you can use the return statement as in function to prematurely exit the function or cancel the function execution. so, in the code i give, when the field is empty it exit the function without calling the next statement.
my mom is javascript, dad is javascripter, granpa is javascriptor, and my little sister is javasRidiculous. my nature language is javascript, then come spanish and english -- me
my apologies, missed a technical detail. replace the double quotes of the alert with single quotes.
my mom is javascript, dad is javascripter, granpa is javascriptor, and my little sister is javasRidiculous. my nature language is javascript, then come spanish and english -- me
my mom is javascript, dad is javascripter, granpa is javascriptor, and my little sister is javasRidiculous. my nature language is javascript, then come spanish and english -- me
Bookmarks