if statement on field attached to radio button

  • djbuzzby365
  • Born
  • Born
  • No Avatar
  • Joined: Feb 01, 2012
  • Posts: 4
  • Status: Offline

Post March 26th, 2012, 5:08 am

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
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post March 26th, 2012, 5:08 am

  • WritingBadCode
  • Graduate
  • Graduate
  • User avatar
  • Joined: Apr 28, 2011
  • Posts: 214
  • Loc: Sweden
  • Status: Offline

Post March 28th, 2012, 3:44 am

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
  • Born
  • Born
  • No Avatar
  • Joined: Feb 01, 2012
  • Posts: 4
  • Status: Offline

Post March 29th, 2012, 10:05 am

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 186 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
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.