Jump to content


Photo

Help building an evaluation system

evaluation system php variables buttons

  • Please log in to reply
2 replies to this topic

#1 Prosjeik

Prosjeik
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 01 November 2013 - 11:27 PM

Hi.

 

I'm going to create a web-based system in php.

 

I wanna put 8 categorys, one on each row and behind each of them there will be 9 buttons.- to the right there vill be a 8x9 cells table.

 

When i press one button the value of that buttons variable will increase with 1.

 

After pressing the button im still at the same page still seeing all those buttons behind the categories. But the value to the button i just pressed will be shown in the table to the right.

 

I may press several buttons a hundred times and the table still show the value (value = how many time i press each button).

 

Can anyone help me on my way? I did work a lot with php for about 10 years ago, but i cant figure out how this could be done..



#2 ignace

ignace
  • Moderators
  • Now mod flavored
  • 6,421 posts
  • LocationBelgium

Posted 02 November 2013 - 09:17 AM

You need JavaScript for this.

<form action="" method="post">
  <input type="button" name="button1" value="1" class="increase-value">
</form>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
  $('.increase-value').click(function() {
    var $this = $(this);
    $this.val(parseInt($this.val(), 10) + 1);
    alert($this.val());
  });
</script>


#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 17,973 posts

Posted 02 November 2013 - 11:31 AM

Are you serious about having to click 72 buttons 100 times to give assessment scores of 100? And if you accidentally overshoot then go round again!

 

Why not text input or dropdowns? This code will give you dropdowns.

<?php
$categories = array(
        1 =>    'Category 1',
        2 =>    'Category 2',
        3 =>    'Category 3',
        4 =>    'Category 4',
        5 =>    'Category 5',
        6 =>    'Category 6',
        7 =>    'Category 7',
        8 =>    'Category 8'
        );
$criteria = array(
        1 =>    'Crit 1',    
        2 =>    'Crit 2',    
        3 =>    'Crit 3',    
        4 =>    'Crit 4',    
        5 =>    'Crit 5',    
        6 =>    'Crit 6',    
        7 =>    'Crit 7',    
        8 =>    'Crit 8',    
        9 =>    'Crit 9'    
        );
$tableHead = "<tr><th>&nbsp;</th><th>" . join('</th><th>', $criteria) . "</th></tr>\n";
$opts = '';
for($i=0; $i<=100; $i++) {
    $v = $i==0 ? '' : $i;
    $opts .= "<option value='$i'>$v</option>";
}
?>
<html>
<head>
<meta name="expires" content= "Sat, 4 Dec 2128 00:00:00 GMT">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta name="generator" content="PhpED Version 8.1 (Build 8115)">
<title>Form sample</title>
<meta name="author" content="Barand">
<meta name="creation-date" content="11/02/2013">
<style type="text/css">
    select {
        width: 50px;
        margin: 3px;
        border: none;
        background-color: #eee;
    }
    th {
        color: white;
        font-weight: 600;
        background-color: #369;
        padding: 2px 4px;
        width: 10%;
    }
    td {
        background-color: #eee;
        padding: 2px 4px;
    }
</style>
</head>
<body>

<h3>Assessment</h3>
<form method="post">
<table cellspacing="1">
    <?php 
        echo $tableHead; 
        foreach ($categories as $catid=>$cat) {
            echo "<tr><td>$cat</td>";
            foreach ($criteria as $cid=>$crit) {
                echo "<td><select name='assess[$catid][$cid]'>$opts</select></td>";
            }
            echo "</tr>\n";
        }
    ?> 
</table>
<input type="submit" name="btnSubmit" value="Submit">
</form>
</body>
</html>

Edited by Barand, 02 November 2013 - 11:32 AM.

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users