0

I am facing a problem with simple validating of radio button though database.

What I want to do is to just simply check whether radio button for each question is selected or not. I know the simple checking. But as I am using php variable name for every radio button name, it's very hard to convert to javascript variable and check. And I am stuck at this point.

<form id="formID" method="post" action="user_anger_quiz.php?rating_finished=true">

<input type="radio" name="<?php echo $question_form_name; ?>" value="<?php echo $question_id ?>,1"/>
<input type="radio" name="<?php echo $question_form_name; ?>" value="<?php echo $question_id ?>,2" />

<p id="anger_rating_submit">
<input type="submit" value="Rate my anger level"/></p>
  </form>

Any suggestions would be appreciated in advanced.

3
  • 2
    Can you give us a little more info on what you mean. Are you checking the radio buttons against correct answers in a db table? or checking them statically. Or when you say validating, do you mean that your code is broken? Can we see some more output? Commented Aug 2, 2011 at 15:15
  • I want to check the users check the radio button or not. thx Commented Aug 2, 2011 at 15:21
  • 1
    You would need to use some javascript. This thread should get you started : stackoverflow.com/questions/2325924/… Commented Aug 2, 2011 at 15:28

2 Answers 2

1

regarding to your comment:

I guess that you will use php to check it due to the fact that you just add php as a tag. In php you can use $_POST or $_GET on action page of your form to fetch the radio buttons.

Otherwise you can use javascript / javascript library

Sign up to request clarification or add additional context in comments.

Comments

1

I think you're asking to make sure there is a radio button checked before submitting? Try the below untested function using jquery to see if there is a radio button selected. Run that before the form is submitted.

function somethingChecked()
{
    if (!$("input[name='<?php echo $question_form_name; ?>']:checked").val()) {
        alert('You need to check something');
        return false;
    } else {
        return true;
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.