0

Hello Guys, I have a codes for Ratings Question Using Radio Button, then i want to do is , if the user missed of the one question to be rated, then its should say, "One Question not Rated!" Can You Check if my Codes is Correct? or is there other way.

Thanks, This is my code

<?php 
 if( isset($_POST['trate1']) AND isset($_POST['trate2']) AND isset($_POST['trate3']) AND isset($_POST['trate4']) AND isset($_POST['trate5']) ) {
      $teamwork = $_POST['trate1'] + $_POST['trate2'] + $_POST['trate3'] + $_POST['trate4'] + $_POST['trate5'];
      $t1 = $_POST['trate1'] * 100;
      $t2 = $_POST['trate2'] * 100;
      $t3 = $_POST['trate3'] * 100;
      $t4 = $_POST['trate4'] * 100;
      $t5 = $_POST['trate5'] * 100;
      $d = $teamwork * 100;

                            echo "<tr>";
                                echo "<th rowspan='5'>TEAMWORK</th>";
                                echo "<td>Communicates with other personnel in an open (being approachable/amiable), candid, clear, complete, consistent, interactive manner - initiates  response/discussion.  Listens effectively, demonstrates genuine interest in others. </td>";
                                echo "<td class='overall1' >$t1 %</td>";
                                echo "<td class='overall' rowspan='5'>$d %</td>";
                                echo "<td class='percentall' rowspan='5'>20%</td>";
                            echo "</tr>";
                            echo "<tr>";
                                echo "<td>Proactively works with team members to improve team collaboration and functioning on a continuous basis </td>";
                                echo "<td class='overall1' >$t2 %</td>";

                            echo "</tr>";
                            echo "<tr>";
                                echo "<td>Communicates with other personnel effectively to establish and maintain smooth working relations.</td>";
                            echo "<td class='overall1' >$t3 %</td>";
                            echo "</tr>";
                            echo "<tr>";
                                echo "<td>Volunteers on committees or projects that are outside typical job responsibilities.</td>";
                                echo "<td class='overall1' >$t4 %</td>";
                            echo "</tr>";
                            echo "<tr>";
                                echo "<td>Provides guidance to others as they work through conflicts and disagreements so they  can become better 'team players' </td>";
                                echo "<td class='overall1' >$t5 %</td>";
                            echo "</tr>";
}
else{
    $error = "Not Rated!";      
                            echo "<tr>";
                                echo "<th rowspan='5'>TEAMWORK</th>";
                                echo "<td>Communicates with other personnel in an open (being approachable/amiable), candid, clear, complete, consistent, interactive manner - initiates  response/discussion.  Listens effectively, demonstrates genuine interest in others. </td>";
                                echo "<td class='overall1' >$error</td>";
                                echo "<td class='overall' rowspan='5'>$error</td>";
                                echo "<td class='percentall' rowspan='5'>20%</td>";
                            echo "</tr>";
                            echo "<tr>";
                                echo "<td>Proactively works with team members to improve team collaboration and functioning on a continuous basis </td>";
                                echo "<td class='overall1' >$error</td>";

                            echo "</tr>";
                            echo "<tr>";
                                echo "<td>Communicates with other personnel effectively to establish and maintain smooth working relations.</td>";
                            echo "<td class='overall1' >$error</td>";
                            echo "</tr>";
                            echo "<tr>";
                                echo "<td>Volunteers on committees or projects that are outside typical job responsibilities.</td>";
                                echo "<td class='overall1' >$error</td>";
                            echo "</tr>";
                            echo "<tr>";
                                echo "<td>Provides guidance to others as they work through conflicts and disagreements so they  can become better 'team players' </td>";
                                echo "<td class='overall1' >$error</td>";
                            echo "</tr>";
}
?>
2
Contributors
2
Replies
17
Views
3 Years
Discussion Span
Last Post by jovstudios
0

Please check the below example...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Questions</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
</head>

<body>

<?php
$numberOfQstns = 5;
$numberOfOptions = 4;
if(isset($_POST['sbtBtn'])){
    echo '<h2>Selected Answers</h2>';
    for($i=1;$i<=$numberOfQstns;$i++) {
        echo '<p>Answer('.$i.'): Question-'.$i.'-Option-'.$_POST["option{$i}"].'</p>';
    }
    echo '<a href=""><< Back >></a>';
}
?>

<form name="myform" id="myform" action="#" method="post" style="width: 160px;display:<?php echo (isset($_POST['sbtBtn'])) ? 'none' : 'block' ?>;">
<?php
for($i=1;$i<=$numberOfQstns;$i++) {
    echo <<<EOD
        <h2>$i; Question-$i</h2>
EOD;
    for($j=1;$j<=$numberOfOptions;$j++) {
        echo <<<EOD
        <input type="radio" name="option{$i}" value="$j"><label>Question-$i-Option-$j</label><br />
EOD;
}
    echo '<hr />';
}

?>
<br />
<input type="submit" value="Submit" name="sbtBtn" id="myBtn" />

</form>
<script type="text/javascript">

    $(document).ready(function() {

    $("#myBtn").click(function(e) {
        var errorMessage="";
        var myCount= 0;
<?php
    for($i=1;$i<=$numberOfQstns;$i++) {
?>      
        if($('input[name=option<?php  echo $i;  ?>]:checked').length<=0)
        {
            if(myCount>0) errorMessage+="\n";
         errorMessage+=(myCount+1)+"; Please Answer Question No:<?php echo $i;  ?>";
         myCount++;
        }
<?php
}       
?>      
    if(errorMessage!="") {
     alert (errorMessage);
     e.preventDefault();
     return false;
     }

    });


    });

</script>

</body>
</html>
0

Thanks Sir, What if I dont Use Array, Because, Every Rating Have A Different Answer, I dont know what to do .. I want like This.

Example:

0 assuming is Radio Button.

Question Number 1 : Please rate: 01 02 03 04 05.

in question number 1, have 4% equivalent percentage, How can i Asign Every radio button value, to the total of 4%.

is this correct?

<input type='radio' name="trate1" value=0.008>1&nbsp;
                                <input type='radio' name="trate1" value=0.016>2&nbsp;
                                <input type='radio' name="trate1" value=0.024>3&nbsp;
                                <input type='radio' name="trate1" value=0.032>4&nbsp;
                                <input type='radio' name="trate1" value=0.04>5



<?php
if( isset($_POST['irate1']) AND isset($_POST['irate2'])) {
      $innovativeness = $_POST['irate1'] + $_POST['irate2'] ;
      $i1 = $_POST['irate1'] * 100;
      $i2 = $_POST['irate2'] * 100;
      $i = $innovativeness * 100;
                            echo "<tr>";
                                echo "<th rowspan='2'>INNOVATIVENESS</th>";
                                echo "<td>Relentlessly challenges the status quo to ensure areas for improvement are identified and addressed </td>";
                                echo "<td class='overall1' >$i1 %</td>";
                                echo "<td class='overall' rowspan='2'>$i %</td>";
                                echo "<td class='percentall' rowspan='2'>10%</td>";
                            echo "</tr>";

Thanks sir. Sorry for my Bad English

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.