Skip to main content
Participant
January 21, 2008
Question

Text box not empty conditional statement

  • January 21, 2008
  • 1 reply
  • 292 views
I've been asked to develop a survey and, in several places, a score is given for the completion of text box. However, if there is no text in the box, then a score of zero should be given.

I thought the best way to do this would be to use a hidden field with a conditional statement saying "if text box is not empty then score=4, else score=0.

However, firstly I'm not sure how to write this and secondly, how do you check if a text box is empty?

I think it really calls for some human input but the client is quite sure this is how he wants it.

The scores are all going to be inserted into a mysql database and sorted out there, so there may be some fudge available there but if php could do something nice in the code, that would be preferable.

Thanks in advance.

Andrew
This topic is closed to new replies. Start a new post to keep the conversation going.

1 reply

Inspiring
January 22, 2008
Drewbles wrote:
> However, firstly I'm not sure how to write this and secondly, how do you check
> if a text box is empty?

Believe it or not, with the PHP function called empty();

http://docs.php.net/manual/en/function.empty.php

if (empty($_POST['fieldName'])) {
// give a score of 0
} else {
// give a positive score
}

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/