if statement on field attached to radio button

  • djbuzzby365
  • Newbie
  • Newbie
  • djbuzzby365
  • Posts: 6

Post 3+ Months Ago

HI there

not sure if that title made sense so i will explain.

i have a section of a form that has a 2 radio buttons: 'YES' and 'NO'. if the 'NO' button is clicked then fine but if the 'YES' button is clicked then an if statement comes into play. attached to the 'YES' is a textfield called 'EXPLAIN' whereby the user gets to go into the answer a little more. i would like some help as to how to write an if statement for that textfield so that if the radio button is clicked then the textfield must be filled in. if it is not then a validation message appears asking for the field to be filled in

Many Thanks

Buzzby
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • WritingBadCode
  • Graduate
  • Graduate
  • User avatar
  • Posts: 214
  • Loc: Sweden

Post 3+ Months Ago

I'm not sure if I understand what you want exactly. You can do something like:

$radioBtnValue = $_POST['radiobutton'];
if ($radioBtnValue == "yes" && empty($_POST['textinput']))
{
echo "error bla bla";
}

This should throw a error IF: YES was selected AND there was no text input in the other field. But only then.

If this was not what you asked for or if this was wierd (you don't get it to work) then post some code and I see if I can make a working example for you.
  • djbuzzby365
  • Newbie
  • Newbie
  • djbuzzby365
  • Posts: 6

Post 3+ Months Ago

Hi there, thats great but i would like exactly the same as javascript as the page i am amending is within a CMS. if you can help then that would be grand. this script is exactly what i need

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 130 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.