updating a textfield based on radio button selection - php
I have some 25 radio buttons, such that only one selection can be done. On selecting a particular radio-button, an ajax update is to be performed on the risk grade textfield of this form. And, this textfield should get uniquely updated on every radio-button selection.
How's this possible. Please, I am really stuck here.
I had done by normal radio button code for each one.
I used the ajax update as done in dependent dropdown textfield, but, I am not sure the same thing is appropriate here.
I think I am getting something wrong here. Any thing would be really helpful.
<table id="department_permissions_table" class="display">
<thead>
<tr style="background-color: lavender"><td style="background-color: white"></td><td><b>Effect</b></td>
<td></td><td></td>
<td></td><td></td></tr>
<tr>
<td style="background-color: lavender"><b>Likelihood of recurrence</b></td>
<td style="background-color: #f5f5f5"><b>Negligible</b></td>
<td style="background-color: #f5f5f5"><b>Minor</b></td>
<td style="background-color: #f5f5f5"><b>Moderate</b></td>
<td style="background-color: #f5f5f5"><b>Major</b></td>
<td style="background-color: #f5f5f5"><b>Catastrophic</b></td>
</tr>
</thead>
<tbody>
<tr>
<td style="background-color: #f5f5f5"><b>Almost certain</b></td>
<td><?php echo $form->radioButton($model,'a11',array('value'=>11,'uncheckValue'=>null)); ?></td>
<td><?php echo $form->radioButton($model,'a11',array('value'=>12,'uncheckValue'=>null)); ?></td>
<td><?php echo $form->radioButton($model,'a11',array('value'=>13,'uncheckValue'=>null)); ?></td>
<td><?php echo $form->radioButton($model,'a11',array('value'=>14,'uncheckValue'=>null)); ?></td>
<td><?php echo $form->radioButton($model,'a11',array('value'=>15,'uncheckValue'=>null)); ?></td>
</tr>
<tr>
<td style="background-color: #f5f5f5"><b>Likely</b></td>
<td><?php echo $form->radioButton($model,'a11',array('value'=>21,
'uncheckValue'=>null,
'ajax' => array(
'type'=>'POST',
'url'=>Yii::app()->createUrl('Cinvestigation/load'),
'update'=>'#risk_grade',
'data'=>array('region_id'=>'js:this.value'),
)
)); ?></td>
<td><?php echo $form->radioButton($model,'a11',array('value'=>22,'uncheckValue'=>null)); ?></td>
<td><?php echo $form->radioButton($model,'a11',array('value'=>23,'uncheckValue'=>null)); ?></td>
<td><?php echo $form->radioButton($model,'a11',array('value'=>24,'uncheckValue'=>null)); ?></td>
<td><?php echo $form->radioButton($model,'a11',array('value'=>25,'uncheckValue'=>null)); ?></td>
</tr>
<tr>
<td style="background-color: #f5f5f5"><b>Possible</b></td>
<td><?php echo $form->radioButton($model,'a11',array('value'=>31,'uncheckValue'=>null)); ?></td>
<td><?php echo $form->radioButton($model,'a11',array('value'=>32,'uncheckValue'=>null)); ?></td>
<td><?php echo $form->radioButton($model,'a11',array('value'=>33,'uncheckValue'=>null)); ?></td>
<td><?php echo $form->radioButton($model,'a11',array('value'=>34,'uncheckValue'=>null)); ?></td>
<td><?php echo $form->radioButton($model,'a11',array('value'=>35,'uncheckValue'=>null)); ?></td>
</tr>
<tr>
<td style="background-color: #f5f5f5"><b>Unlikely</b></td>
<td><?php echo $form->radioButton($model,'a11',array('value'=>41,'uncheckValue'=>null)); ?></td>
<td><?php echo $form->radioButton($model,'a11',array('value'=>42,'uncheckValue'=>null)); ?></td>
<td><?php echo $form->radioButton($model,'a11',array('value'=>43,'uncheckValue'=>null)); ?></td>
<td><?php echo $form->radioButton($model,'a11',array('value'=>44,'uncheckValue'=>null)); ?></td>
<td><?php echo $form->radioButton($model,'a11',array('value'=>45,'uncheckValue'=>null)); ?></td>
</tr>
<tr>
<td style="background-color: #f5f5f5"><b>Rare</b></td>
<td><?php echo $form->radioButton($model,'a11',array('value'=>51,'uncheckValue'=>null)); ?></td>
<td><?php echo $form->radioButton($model,'a11',array('value'=>52,'uncheckValue'=>null)); ?></td>
<td><?php echo $form->radioButton($model,'a11',array('value'=>53,'uncheckValue'=>null)); ?></td>
<td><?php echo $form->radioButton($model,'a11',array('value'=>54,'uncheckValue'=>null)); ?></td>
<td><?php echo $form->radioButton($model,'a11',array('value'=>55,'uncheckValue'=>null)); ?></td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
<table class="table">
<tbody>
<tr>
<td><div class="span2" style="width:auto; margin-top:5px; margin-bottom: 5px">Grade risk: </div></td>
<td><?php echo $form->textFieldRow($model,'risk_grade',array('class'=>'span2','maxlength'=>100)); ?>
</td>
</tr>
<tr>
I don't think you need ajax update for this task. You could easily do it with jQuery, you just need to have some kind of mapper for radio button values and string you want to set for the text field
First set the class for each radio button
<?php echo $form->radioButton($model,'a11',array('value'=>51,'uncheckValue'=>null, 'class'=>'radioClass')); ?>
Than set the class for textfield
<?php echo $form->textFieldRow($model,'risk_grade',array('class'=>'textClass span2','maxlength'=>100)); ?>
Then attach event listener in javascript
<script>
$(function(){
$(".radioClass").click(function(){
$(".textClass").val($(this).val());
});
});
</script>
This code will but clicked radio button value into textfield's value
Now you may need some kind of mapper for radio button values and the text you want to display, which may be generated by the server side
I hope I helped
Related
How can i use the a tag
I have some code and would like to add an hyperlink to each entry on my database tried using the 'a' tag <tr> <td><?php echo $row['id']; ?></td> <td><a href='details.php'><?php echo $row['game_name']; ?></a></td> <td><?php echo $row['game_year']; ?></td> <td><?php echo $row['system']; ?></td> <td style="text-align: center; color:green"><?php echo $row['owned']; ?></td> <td style="text-align: center; color:blue"><?php echo $row['completed']; ?></td> <td><?php echo $row['media']; ?></td> <td><?php echo $row['launcher']; ?></td> <tr> would like to be able to link to a details page
<a href='details.php?gameID=<?=$row['id']?>'> And in your details.php page you could fetch your DB: $gameID = (int)$_GET['gameID'] and a bit more error handling
PHP table (Date) dynamic color change based on validity
<div class="table-responsive"> <table id="Well_CAT" class="table table-striped table-bordered"> <thead> <th>Client_Contract_Number</th> <th>Currently_Using</th> <th>MBPS_EAM_Number_RIGT</th> <th>Model_and_Type</th> <th>LFour_Yearly</th> <th>Six_Monthly</th> <th>One_Yearly</th> <th>One_and_Half_Yearly</th> <th>Two_Yearly</th> <th>Two_and_Half_Yearly</th> <th>Three_Yearly</th> <th>Three_and_Half_Yearly</th> <th>Four_Yearly</th> <th>Remarks</th> </thead> <?php while($rows=mysql_fetch_array($result)){ ?><tr> <td class="exdate"><? echo $rows['Client_Contract_Number']; ?></td> <td class="exdate"><? echo $rows['Currently_Using']; ?></td> <td><? echo $rows['MBPS_EAM_Number_RIGT']; ?></td> <td><? echo $rows['Model_and_Type']; ?></td> <td><? echo $rows['LFour_Yearly']; ?></td> <td class="exdate"><? echo $rows['Six_Monthly']; ?></td> <td class="exdate"><? echo $rows['One_Yearly']; ?></td> <td class="exdate"><? echo $rows['One_and_Half_Yearly']; ?></td> <td class="exdate"><? echo $rows['Two_Yearly']; ?></td> <td class="exdate"><? echo $rows['Two_and_Half_Yearly']; ?></td> <td class="exdate"><? echo $rows['Three_Yearly']; ?></td> <td class="exdate"><? echo $rows['Three_and_Half_Yearly']; ?></td> <td class="exdate"><? echo $rows['Four_Yearly']; ?></td> <td class="exdate"><? echo $rows['Remarks']; ?></td> </tr> <?php } ?> </table> Below is my table, it is to track the validity of certificates, columns from Lfour yearly till Fouryearly are date fields, i would like to conditional color format these fields based on validity... Like If valid - Green, Expired - Red.
Since PHP >= 5.2.0 you can use the DateTime class as such: if (new DateTime() > new DateTime("2010-05-15 16:00:00")) { # current time is greater than 2010-05-15 16:00:00 # in other words, 2010-05-15 16:00:00 has passed } The string passed to the DateTime constructor is parsed according to these rules. Here is an example with your code: <td class="exdate" style="color:<?php echo (new DateTime() > new DateTime($rows['Six_Monthly'])) ? 'red' : 'green'; ?>;" ><? echo $rows['Six_Monthly']; ?></td>
Bootstrap table not cropping for tablet devices
I'm using Twitter-Bootstrap for a table. The table works fine for bigger screens and for mobile. For tablet it doesn't work. What I want is the following: The image above is how it is on mobile. I want this too for tablet, but when I select tablet resolution on Chrome I get this: It's not responsive. How can I fix this? Code: <div class="table-responsive"> <table class="table"> <thead> <tr> <th>Breedte</th> <th>Hoogte</th> <th>Doekkleur</th> <th>Omkastingkleur</th> <th>Bedieningtype</th> <th>Bedieningkant</th> <th>Uitvoer</th> <th>Geleider links</th> <th>Geleider rechts</th> <th>Opvulling</th> <th>Onderlat-type</th> <th>Extra</th> <th>Prijs</th> <th>Actie</th> </tr> </thead> <tbody> <?php foreach ($result as $offer) { ?> <tr> <td><?php echo $offer['width'] ?></td> <td><?php echo $offer['height'] ?></td> <td><?php echo $offer['clothingcolor'] ?></td> <td><?php echo $offer['housingcolor'] ?></td> <td><?php echo $offer['controltype'] ?></td> <td><?php echo $offer['controlside'] ?></td> <td><?php echo $offer['output'] ?></td> <td><?php echo $offer['conductorleft'] ?></td> <td><?php echo $offer['conductorright'] ?></td> <td><?php echo $offer['stuffing'] ?></td> <td><?php echo $offer['underlattype'] ?></td> <td><?php echo $offer['extra'] ?></td> <td><?php echo $offer['price'] ?></td> <td><button type="submit" class="btn btn-link" name="getValue" data-toggle="modal" data-target=".editProduct<?php echo $offer['id']; ?>" data-id="<?php echo $offer['id']; ?>"><i class="fa fa-pencil" aria-hidden="true" style="color: red;"></i></a></td> </tr> <?php } ?> </tbody> </table> </div>
Change row color of a table based on mysqli value using materializecss
I'm using Materialize css on my project, i have a table that shows mysql field called "status" and in this table i want change the color of the row if i change the "status" like "1=blue, 2=red..." Someone here knows how i can make a function to do this? Thank you. table extample: table class="striped bordered responsive-table"> <thead> <tr> <th>ID</th> <th>Cliente</th> <th>Objeto</th> <th>Status</th> </tr> </thead> <tbody> <?php while($row_os = mysqli_fetch_assoc($result_user)){?> <tr> <td><?php echo $row_os["num"]; ?></td> <td><?php echo $row_os["cliente"]; ?></td> <td><?php echo $row_os["object"]; ?></td> <td><?php echo $row_os["status"]; ?></td> </tr> <?php } ?> </tbody>
One simple way would be: <?php $colorMap = [ 1 => 'blue', 2 => 'red', // add more ]; while ($row_os = mysqli_fetch_assoc($result_user)) { ?> <tr style="background:<?php echo $colorMap[$row_os['status']] ?>"> <td><?php echo $row_os["num"]; ?></td> <td><?php echo $row_os["cliente"]; ?></td> <td><?php echo $row_os["object"]; ?></td> <td><?php echo $row_os["status"]; ?></td> </tr> <?php } ?> Of course you could also add a class depending on status the same way and do the styling in CSS.
Simple as Doing this on the row , only if the status must contain a value of either 1 or 2 <?php while($row_os = mysqli_fetch_assoc($result_user)){?> <tr class="<?php echo $row_os["status"]==1?'blue':'red'?> lighten-2"> <td><?php echo $row_os["num"]; ?></td> <td><?php echo $row_os["cliente"]; ?></td> <td><?php echo $row_os["object"]; ?></td> <td><?php echo $row_os["status"]; ?></td> </tr> <?php } ?> or if status varies (then follow #colburton answers ) or this <?php while($row_os = mysqli_fetch_assoc($result_user)){ $color=""; switch($row_os["status"]){ case 1: $color="blue"; break; case 2: $color="red"; break; //and so on } ?> <tr class="<?php echo $color;?> lighten-2"> <td><?php echo $row_os["num"]; ?></td> <td><?php echo $row_os["cliente"]; ?></td> <td><?php echo $row_os["object"]; ?></td> <td><?php echo $row_os["status"]; ?></td> </tr> <?php } ?>
Weird table repeating when displaying mysql results
There's nothing wrong with the result itself. The image should explain itself. The table basicly is repeating the whole table for each results instead of displaying the results with multiple lines on one table, its doing 1 line on 1 table many times. Here's the code that involves it- <?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"id"); $f2=mysql_result($result,$i,"date"); $f3=mysql_result($result,$i,"agentclient"); $f4=mysql_result($result,$i,"propertydescription"); $f5=mysql_result($result,$i,"transactiontype"); $f5=mysql_result($result,$i,"applicabledocument"); $f5=mysql_result($result,$i,"received"); $f5=mysql_result($result,$i,"paid"); ?> <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr valign="bottom" bgcolor="#000000"> <td width="24"><span class="style1b"><strong>No.</strong></span></td> <td width="105"><span class="style1b"><strong>Date</strong></span></td> <td width="57"><span class="style1b"><strong>Agent/client</strong></span></td> <td width="170"><span class="style1b"><strong>Property/Description</strong></span></td> <td width="199"><span class="style1b"><strong>Transaction type </strong></span></td> <td width="235"><span class="style1b"><strong>Applicable document </strong></span></td> <td width="58"><span class="style1b"><strong>Received</strong></span></td> <td width="58"><span class="style1b"><strong>Paid</strong></span></td> </tr> <tr valign="top" bgcolor="#FFFFFF"> <td><?php echo $f1; ?></td> <td><?php echo $f2; ?></td> <td><?php echo $f3; ?></td> <td><?php echo $f4; ?></td> <td><?php echo $f5; ?></td> <td><?php echo $f6; ?></td> <td><?php echo $f7; ?></td> <td><?php echo $f8; ?></td> </tr> </table> <?php $i++; } ?>
There are lots of way to improve this code, but to fix your immediate problem, just take the header row out of the loop: <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr valign="bottom" bgcolor="#000000"> <td width="24"><span class="style1b"><strong>No.</strong></span></td> <td width="105"><span class="style1b"><strong>Date</strong></span></td> <td width="57"><span class="style1b"><strong>Agent/client</strong></span></td> <td width="170"><span class="style1b"><strong>Property/Description</strong></span></td> <td width="199"><span class="style1b"><strong>Transaction type </strong></span></td> <td width="235"><span class="style1b"><strong>Applicable document </strong></span></td> <td width="58"><span class="style1b"><strong>Received</strong></span></td> <td width="58"><span class="style1b"><strong>Paid</strong></span></td> </tr> <?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"id"); $f2=mysql_result($result,$i,"date"); $f3=mysql_result($result,$i,"agentclient"); $f4=mysql_result($result,$i,"propertydescription"); $f5=mysql_result($result,$i,"transactiontype"); $f5=mysql_result($result,$i,"applicabledocument"); $f5=mysql_result($result,$i,"received"); $f5=mysql_result($result,$i,"paid"); ?> <tr valign="top" bgcolor="#FFFFFF"> <td><?php echo $f1; ?></td> <td><?php echo $f2; ?></td> <td><?php echo $f3; ?></td> <td><?php echo $f4; ?></td> <td><?php echo $f5; ?></td> <td><?php echo $f6; ?></td> <td><?php echo $f7; ?></td> <td><?php echo $f8; ?></td> </tr> <?php $i++; } ?> </table>