Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Text box not empty conditional statement

New Here ,
Jan 21, 2008 Jan 21, 2008
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
TOPICS
Server side applications
294
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 22, 2008 Jan 22, 2008
LATEST
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/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines