|
-
Jul 22nd, 2005, 05:50 AM
#1
Thread Starter
Addicted Member
Javascript: Check at least two textboxes are full
Hey, i have 4 textfields and i need to check that at least two of them are full.
Would it b better to check it client-side using JS or server-side using PHP?
Can anyone please help??
Thanks
-
Jul 22nd, 2005, 06:33 AM
#2
PowerPoster
Re: Javascript: Check at least two textboxes are full
Server Side using PHP, since people can simply turn off Javascript. For convience you can check client side as well, saves the user submitting the form only to find its not done right, and its reduces the amount of work the server has to do, since almost always its going to be full.
-
Jul 22nd, 2005, 06:47 AM
#3
Thread Starter
Addicted Member
Re: Javascript: Check at least two textboxes are full
OK, so... say i do it with Javascript, how do i check that at least 2 of the 4 textfields are not empty.
And also, how would i do it with PHP if anyone know?
Thanks, if you know how to do it with either of the languages i would be most grateful
BIOSTALL
-
Jul 22nd, 2005, 06:53 AM
#4
PowerPoster
Re: Javascript: Check at least two textboxes are full
Are not empty? Not Empty in Javascript is easy, but if you want greater-than-certain-length then it gets abit harder I think, I can't remember all the javascript functions.
No gurantees that the code is right, I'm to lazy to test.
Code:
//Javascript
if(document.formname.textboxname.value != '') {
alert('not empty');
}
To check atleast 4 aren't empty, you could use a variable to count how many times a textbox is found to be empty (or not empty whichever way you want to look at it ), and after you've done checking each you can check if the variable is greater than 2 or not.
Code:
//PHP
if(trim($_GET["mytextboxname"]) != "") {
print "No Nullness today :)";
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|