On 10/2/11, Hamurabi Web Tech. <[email protected]> wrote:
> @Garrett,
> If I use submit button, then I can't check the form inputs using Javascript
> to validate values.
> Lets say for example I want to check wether the <input type="text"
> name="username" id="username" /> is empty? currently I use PHP to validate
> this but I wish I can do it in Javascript:

You need to do it on the server. You can do it on the client, too, but
that is for the users' convenience.

> if( document.getElementById('username').value == '')
>     alert('Please enter your username');
> else
>    form.submit();
>
> Any alternative way to check using JS?
>
Use `onsubmit` and return false.

<form onsubmit="return validateForm(this);">

Don't use XHTML. See also http://hixie.ch/advocacy/xhtml
-- 
Garrett

-- 
You received this message because you are subscribed to the Google Groups 
"iPhoneWebDev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/iphonewebdev?hl=en.

Reply via email to