Check/Uncheck all checkboxes with Javascript in a PHP array with keys - php

I have the following code:
Check All |
Uncheck All |
Invert Selection<br />
<table>
<tr>
<td><input type="checkbox" name="names[8]" value="yes" />Paul</td>
<td><input type="checkbox" name="names[11]" value="yes" />Bob</td>
<td><input type="checkbox" name="names[44]" value="yes" />Tom</td>
</tr>
</table>
And the following script:
function setCheckboxes3(act)
{
elts = document.getElementsByName("names[]");
var elts_cnt = (typeof(elts.length) != 'undefined') ? elts.length : 0;
if (elts_cnt)
{
for (var i = 0; i < elts_cnt; i++)
{
elts[i].checked = (act == 1 || act == 0) ? act : (elts[i].checked ? 0 : 1);
}
}
}
The script is working with other arrays without keys, but I can't get it to work with this array which has keys.
Thanks in advance

You can use getElementsByClassName:
<script type="text/javascript" language="javascript">
function setCheckboxes3(act) {
var e = document.getElementsByClassName('names');
var elts_cnt = (typeof(e.length) != 'undefined') ? e.length : 0;
if (!elts_cnt) {
return;
}
for (var i = 0; i < elts_cnt; i++) {
e[i].checked = (act == 1 || act == 0) ? act : (e[i].checked ? 0 : 1);
}
}
</script>
Check All |
Uncheck All |
Invert Selection<br />
<input type="checkbox" name="names[8]" class="names" value="yes" />Paul
<input type="checkbox" name="names[11]" class="names" value="yes" />Bob
<input type="checkbox" name="names[44]" class="names" value="yes" />Tom
OR you can use: getElementsByTagName
<script type="text/javascript" language="javascript">
function setCheckboxes3(act) {
var e = document.getElementsByTagName('input');
var elts_cnt = (typeof(e.length) != 'undefined') ? e.length : 0;
if (!elts_cnt) {
return;
}
for (var i = 0; i < elts_cnt; i++) {
if((e[i].type) == 'checkbox') {
e[i].checked = (act == 1 || act == 0) ? act : (e[i].checked ? 0 : 1);
}
}
}
</script>
Check All |
Uncheck All |
Invert Selection<br />
<input type="checkbox" name="names[8]" value="yes" />Paul
<input type="checkbox" name="names[11]" value="yes" />Bob
<input type="checkbox" name="names[44]" value="yes" />Tom
Did you get a chance to try jQuery?

Related

How can I submit form using ajax

I want to show the output of polldemo1.php on poll.php page. But it is not happening. It is showing the poll.php page's form again as output.
Please correct it.Also if anyone can explain me php with ajax, it would be really nice
poll.php
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
</head>
<body>
<h3>SIG Polls</h3>
<form method="POST" id="myform" class="myform" >
C/C++
<input type="checkbox" name="vote[]" value="0" />
<br />
Java
<input type="checkbox" name="vote[]" value="1" />
<br />
Matlab
<input type="checkbox" name="vote[]" value="2" />
<br />
C#/.NET
<input type="checkbox" name="vote[]" value="3" />
<br />
PHOTOSHOP
<input type="checkbox" name="vote[]" value="4" />
<br />
CCNA
<input type="checkbox" name="vote[]" value="5" />
<br />
BASIC ELECTRONICS
<input type="checkbox" name="vote[]" value="6" />
<br />
<input type="submit" name="submit" value="vote" onclick="return submitForm()" />
</form>
<div id="myResponse"></div>
<script type="text/javascript">
function submitForm() {
var form = document.myform;
var dataString = $(form).serialize();
$.ajax({
type:'POST',
url:'polldemo1.php',
data: dataString,
success: function(data){
$('#myResponse').text(data);
}
});
return false;
}
</script>
</body>
</html>
polldemo1.php
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
</head>
<?php
echo "hello";
//error_reporting(0);
if(isset($_POST['submit']))
{
/*if (isset($_COOKIE["ieeepoll"]))
{
echo "<script>alert('You have already voted'); location.href='poll.php';</script>";
} */
//get content of textfile
$filename = "poll_result.txt";
$content = file($filename);
//put content in array
$array = explode("||", $content[0]);
$c = $array[0];
$java = $array[1];
$matlab = $array[2];
$net = $array[3];
$ph = $array[4];
$ccna = $array[5];
$be = $array[6];
foreach($_POST["vote"] as $vote)
{
if ($vote == 0)
{
$c = $c + 1;
}
if ($vote == 1)
{
$java = $java + 1;
}
if ($vote == 2)
{
$matlab = $matlab + 1;
}
if ($vote == 3)
{
$net = $net + 1;
}
if ($vote == 4)
{
$ph = $ph + 1;
}
if ($vote == 5)
{
$ccna = $ccna + 1;
}
if ($vote == 6)
{
$be = $be + 1;
}
}
//insert votes to txt file
$insert = $c."||".$java."||".$matlab."||".$net."||".$ph."||".$ccna."||".$be;
file_put_contents($filename,$insert);
echo $be;
}
?>
Add onsubmit event in for html form attribute as following
<form method="POST" id="myform" class="myform" onsubmit="return false" >
You can manage above thing by jQuery also, just need to modify your javascript code something like this.
$("#myform").on('submit', function (event) {
event.preventDefault();
$.ajax({
type: 'POST',
url: 'polldemo1.php',
data: $("#myform").serialize(),
success: function (data, status) {
//do whatever you want to do
},
error: function (err) {
//do wahtever you want to do
}
});
});
//OR
$("#myform").on('submit', function (event) {
event.preventDefault();
submitForm();
});
Also you don't need to keep any html attribute in you php script. Remove all html tags from that script.
try this it should help you.it will display the content of the file on poll.php on submit of form.
poll.php
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
</head>
<body>
<h3>SIG Polls</h3>
<form method="POST" id="myform" class="myform" >
C/C++
<input type="checkbox" name="vote[]" value="0" />
<br />
Java
<input type="checkbox" name="vote[]" value="1" />
<br />
Matlab
<input type="checkbox" name="vote[]" value="2" />
<br />
C#/.NET
<input type="checkbox" name="vote[]" value="3" />
<br />
PHOTOSHOP
<input type="checkbox" name="vote[]" value="4" />
<br />
CCNA
<input type="checkbox" name="vote[]" value="5" />
<br />
BASIC ELECTRONICS
<input type="checkbox" name="vote[]" value="6" />
<br />
<input type="submit" name="submit" value="vote" onclick="return submitForm()" />
</form>
<div id="myResponse"></div>
<script type="text/javascript">
function submitForm() {
var dataString = $("#myform").serialize();
$.ajax({
type:'POST',
url:'index.php',
data: dataString,
success: function(data){
$('#myResponse').text(data);
}
});
return false;
}
</script>
</body>
</html>
polldemo1.php
<?php
echo "hello";
//error_reporting(0);
if(isset($_POST))// do not check for submit here it won't go with post
{
/*if (isset($_COOKIE["ieeepoll"]))
{
echo "<script>alert('You have already voted'); location.href='poll.php';</script>";
} */
//get content of textfile
$filename = "poll_result.txt";
$content = file($filename);
//put content in array
$array = explode("||", $content[0]);
$c = $array[0];
$java = $array[1];
$matlab = $array[2];
$net = $array[3];
$ph = $array[4];
$ccna = $array[5];
$be = $array[6];
foreach($_POST["vote"] as $vote)
{
if ($vote == 0)
{
$c = $c + 1;
}
if ($vote == 1)
{
$java = $java + 1;
}
if ($vote == 2)
{
$matlab = $matlab + 1;
}
if ($vote == 3)
{
$net = $net + 1;
}
if ($vote == 4)
{
$ph = $ph + 1;
}
if ($vote == 5)
{
$ccna = $ccna + 1;
}
if ($vote == 6)
{
$be = $be + 1;
}
}
//insert votes to txt file
$insert = $c."||".$java."||".$matlab."||".$net."||".$ph."||".$ccna."||".$be;
file_put_contents($filename,$insert);
echo $insert;
}
?>

why doesnt my form value's added to mysql / and how to get 2 decimals at calculation

1.can someone find why the form doesnt add/submit the values to database ?
i have tried adding values by the form and testing but its not getting in the database
2.and on calculation i get soms values with more than 2 decimals how to fix that because at the script/code i have decimals on 2 maybe someone ?
screenshot of decimals http://prntscr.com/5fbedf
<html>
<head>
</head><body>
<?php require "config.php" ; ?>
<?php require "admin_menu.php" ;?>
<?php
if(isset($_POST['verzenden']))
{
$id = addslashes($_POST['id']);
$flesnummer = addslashes($_POST['flesnummer']);
$begin_gewicht = addslashes($_POST['begin_gewicht']);
$verbruikt = addslashes($_POST['verbruikt']);
$eind_gewicht = addslashes($_POST['eind_gewicht']);
$verschil = addslashes($_POST['verschil']);
$tara_gewicht = addslashes($_POST['tara_gewicht']);
$over = addslashes($_POST['over']);
mysql_query("INSERT INTO Flesnummer (id, flesnummer, begin_gewicht, verbruikt, eind_gewicht, verschil, tara_gewicht, over) VALUES ('".$id."', '".$flesnummer."', '".$begin_gewicht."', '".$verbruikt."', '".$eind_gewicht."', '".$verschil."', '".$tara_gewicht."', '".$over."')");
echo '<br><br><br>Fles succesvol toegevoegd';
}
else
{
?>
<script>
function totaalIt() {
var x = document.getElementById("begin_gewicht").value;
var y = document.getElementById("tara_gewicht").value;
var z = document.getElementById("verbruikt").value;
var w = document.getElementById("eind_gewicht").value;
if ((isNumeric(x, true)) && (isNumeric(y, true)) && (isNumeric(z, true))&& (isNumeric(w, true))) {
x = parseFloat(x);
y = parseFloat(y);
z = parseFloat(z);
w = parseFloat(w);
var wverschil = x - y - z + y - w
var xyzover = x - y - z
var xyztotaal = x - y - z + y;
document.getElementById("verschil").value = wverschil;
document.getElementById("over").value = xyzover;
document.getElementById("totaal").value = xyztotaal;
if (confirm ("Formule: Begin gewicht - tara gewicht = vulling - verbruikt = vulling over + tara gewicht = totaal - eind gewicht = verschil(verlies) ?")) {
document.getElementById("form1").submit();
}
} else {
alert("Numeric Values must be entered.");
}
}
function isNumeric(sText, decimalAllowed) {
if (sText.length == 0) return false;
var validChars = "";
if (decimalAllowed) {
validChars = "0123456789.";
} else {
validChars = "0123456789";
}
var isNumber = true;
var charA;
var decimalCount = 0;
for (i = 0; i < sText.length && isNumber == true && decimalCount < 2; i++) {
charA = sText.charAt(i);
if (charA == ".") {
decimalCount += 1;
}
if (validChars.indexOf(charA) == -1) {
isNumber = false;
}
}
return isNumber;
}
</script>
<form name="form1" id="form1" action=" <?=$_SERVER['PHP_SELF']?> " method="POST">
<table>
<input type="hidden" name="id" >
<tr><td>Flesnummer:</td><td><input name="flesnummer" id="flesnummer" type="text" size"4">
<tr><td>Begin gewicht:</td><td><input name="begin_gewicht" type="text" id="begin_gewicht" size="4" />
Kg</td></tr>
<tr><td>Tara gewicht:</td><td><input name="tara_gewicht" type="text" id="tara_gewicht" size="4" />
Kg</td></tr>
<tr><td>Verbruik:</td><td><input name="verbruikt" type="text" id="verbruikt" size="4" />
Kg</td></tr>
<tr><td>Vulling over:</td><td><input name="over" type="text" id="over" size="4" readonly="true" />
Kg (automatisch berekend)</td></tr>
<tr><td>Eind gewicht:</td><td><input name="eind_gewicht" type="text" id="eind_gewicht" size="4" />
Kg</td></tr>
<tr><td>Eind gewicht: <img title="Eindgewicht volgens berekening" src="img/question.gif" width="15" height="15" onMouseDown="Eindgewicht volgens berekening" alt="Eindgewicht volgens berekening." /></td><td><input name="totaal" type="text" id="totaal" size="4" readonly="true" />
Kg (automatisch berekend)</td></tr>
<tr><td>Verschil(verlies):</td><td><input name="verschil" type="text" id="verschil" size="4" readonly="true" />
Kg (automatisch berekend)</td></tr>
<tr><td><input type="button" name="verzenden" id="verzenden" value="Verzenden" onClick="totaalIt()" /></td></tr>
</table></form>
<?
}
?>
On your form, try turning your button input to submit:
<input type="button" name="verzenden" id="verzenden" value="Verzenden" onClick="totaalIt()" />
TO:
<input type="submit" name="verzenden" id="verzenden" value="Verzenden" onClick="totaalIt()" />
Your button is not registering the name so it's not getting to the $_POST['verzenden'] in your check:
// There is no $_POST['verzenden'] with the button.
if(isset($_POST['verzenden'])) {

Calculate my dynamic and my static input together

I have a function static who can calculate all my static input:
$('document').ready(function() {
$('#input5,#tempsam ').each(function () {
$(this).on('change',recalculate);
});
});
function recalculate () {
if(isNaN(this.value))
alert("Please enter a number");
else {
var b = 0;
if (($('#input5').val() !== b) && ($('#input2').val() !== b) && ($('#tempsam').val() !== b )) {
var a = 40;
var value1 = $('#input1').val() == "" ? 0 : parseFloat($('#input1').val());
var value7 = $('#tempsam').val() == "" ? 0 : parseFloat($('#tempsam').val());
var total = value5 + value2 + value7
$('#result').val(total);
}
}
}
How I calculate my dynamic input and my static one?
Here is how I calculate my static one each day:
//jeudi calcul
function checkfieldjeudi()
{
var dynamicjeudi = document.getElementsByClassName("dynamicjeudi");
var itemCount5 = dynamicjeudi.length;
var total = 0;
for(var i = 0; i < itemCount5; i++) {
total = total + parseFloat(dynamicjeudi[i].value);
total = total + parseFloat(document.getElementById('input5').value);
}
document.getElementById('totaljeudi').value = total;
}
checkfieldjeudi();
How I make dynamic jeudi
$('#calculTempsdivjeu').append(
( '<input id="calculTempsdivjeu' + counterjeudi + '" name="calculTempsdivjeu[]' + '" type="number" onchange="checkfieldjeudi();" size="10" min="0" max="24" value="0" class="dynamicjeudi" onblur="autre();" onfocus="enter();"/>')
) //désactive champs précédent.
Here my static jeudi
<div id="calculTempsdivjeu">
<input step="any" type="number" id="totaljeudi" class="totaljeudi" onchange="checkfieldjeudi();" name="totaljeudi" size="10" min="0" max="24" value="0" onblur="autre();" onfocus="enter();"/>
<input step="any" type="number" onblur="autre();" onfocus="enter();" onchange="checkfieldjeudi();" id="input5" class="temps" name="tempsje" max="24" min="0" value="0" />
</div>

form $_POST error, dynamic fields

I have an error that I can't figure out...
Om my webpage there is a form that the user has the ability to add some new input fields to. If the user is submitting the form, then the optional fields is empty when the php-file is handing them, why?
HTML:
<form method="post" action="newRequest.php">
<input type="text" name="title" />
<input type="hidden" name="fname" value="0" />
<input type="checkbox" name="fname" value="1"/>
<input type="hidden" name="ename" value="0" />
<input type="checkbox" name="ename" value="1" />
<input type="hidden" name="seat" value="0" />
<input type="checkbox" name="seat" value="1" />
<input type="hidden" name="fields" value="0" />
<input type="text" id="fields" name="fields" />
<input type="submit" />
</form>
PHP:
if (strlen($_POST[title]) > 2) {
$toDb[title] = $_POST[title];
} else {
error('title');
}
$toDb[fname] = $_POST[fname];
$toDb[ename] = $_POST[ename];
$toDb[seat] = $_POST[seat];
if ($_POST[fields] > 0) {
$i = 0;
while ($i < $_POST[fields]) {
$toDb[optional][$i] = $_POST[optional-$i];
$i++;
}
$toDb[optional] = serialize($toDb[optional]);
} else {
$toDb[optional] = 0;
}
newEvent($toDb,$dbh);
JQuery that is adding dynamical fields:
$(document).ready(function() {
$('#fields').focusout(function(){
var fields = $('#fields').val();
var i = 0;
while(i < fields) {
$('#fields').after("Valfritt fält "+(i+1)+":<input type='text' name='optional"+i+"' />");
i++;
}
})
})
You should quote array indexes. It should be
$toDb['optional'][$i] = $_POST['optional'.$i];
You are missing commas in $_POST
$toDb['fname'] = $_POST['fname'];
$toDb['ename'] = $_POST['ename'];
$toDb['seat'] = $_POST['seat'];
Here is your modified code
if (strlen($_POST['title']) > 2) {
$toDb['title'] = $_POST['title'];
} else {
error('title');
}
$toDb['fname'] = $_POST['fname'];
$toDb['ename'] = $_POST['ename'];
$toDb['seat'] = $_POST['seat'];
if (count($_POST) > 0) {
$i = 0;
while ($i < count($_POST)) {
$toDb['optional'][$i] = $_POST['optional-'.$i];
$i++;
}
$toDb['optional'] = serialize($toDb['optional']);
} else {
$toDb['optional'] = 0;
}
newEvent($toDb,$dbh);
Also use count() to check if $_POST has values > 0.
I faced the same problem and I solved it using Javascript, like this :
add a new text field every time a button is pressed

automatic submit form js

I'm trying to auto submit a form,(below it's only the form, its wrapped with a while{} for each DB entry to display).
It's working for all days of the week, but I can't submit the value for $totalhours, $holidayhours, $wagegross without a js event like onfocus().
Basically I want to submit this 3 inputs without an click or any other manual action.
any idea ?
<form id="weeklysheet" name="weeklysheet" method="post" action="hourly-function.php">
<tbody>
<tr style="line-height:0px;">
<td class="large">
<p class="employee_name"><?php echo $fullname?></p>
</td>
<td class="small">
<input name="mon" id="mon" type="text" class="days_input" value="<?php echo $data['mon'];?>"onchange="this.form.submit();"/>
</td>
<td class="small">
<input name="tue" id="tue" type="text" class="days_input" value="<?php echo $data['tue'];?>"onchange="this.form.submit();"/>
</td>
<td class="small">
<input name="wed" id="wed" type="text" class="days_input" value="<?php echo $data['wed'];?>"onchange="this.form.submit();"/>
</td>
<td class="small">
<input name="thu" id="thu" type="text" class="days_input" value="<?php echo $data['thu'];?>"onchange="this.form.submit();"/>
</td>
<td class="small">
<input name="fri" id="fri" type="text" class="days_input" value="<?php echo $data['fri'];?>"onchange="this.form.submit();"/>
</td>
<td class="small">
<input name="sat" id="sat" type="text" class="days_input" value="<?php echo $data['sat'];?>"onchange="this.form.submit();"/>
</td>
<td class="small">
<input name="sun" id="sun" type="text" class="days_input" value="<?php echo $data['sun'];?>"onchange="this.form.submit();"/>
</td >
<td class="small">
<input name="totalhours" id="totalhours" type="text" class="cumul_week_input" value="<?php echo $totalhours ?>"onfocus="this.form.submit();"/>
</td>
<td class="small">
<input name="holidayhours" type="text" class="cumul_week_input" value="<?php echo $holidayhours ?>"onfocus="this.form.submit();"/>
</td>
<td class="small">
<input name="wagegross" type="text" class="cumul_week_input" value="<?php echo $wagegross ?>"onfocus="this.form.submit();"/>
</td>
<td>
<input type="submit"name="save" id="save" value="Confirm" style="display:none;" />
</tr>
</tbody>
</form>
You could use jQuery to trigger the submit button's click action after the document has loaded like so:
1.) You can link the jQuery library from Google's Hosted Libraries:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
or, download it from jQuery.com to, say a "js" folder, and include it
<script src="js/jQuery.js"></script>
2.) Place this script tag at below the </form> tag:
<script type="text/javascript">
$(document).ready(function(){ //When the document is done loading
$("input#save").trigger('click'); //"Click" on the input button with an ID of "save"
});
</script>
Or you could do it the pure javascript way without jQuery like so:
<html>
<body onLoad="submitform()">
<form id="weeklysheet" name="weeklysheet" method="post" action="hourly-function.php">
Then place this script tag below the </form> tag:
<script type="text/javascript">
function submitform()
{
document.weeklysheet.submit();
}
</script>
Or, to shorten the method above:
<html>
<body onLoad="Javascript: document.weeklysheet.submit();">
<form id="weeklysheet" name="weeklysheet" method="post" action="hourly-function.php">
Are you looking to submit them individually or all at once? If you want to do it all at once you could give the last element an id and in jquery use $('#div').moueleave
that's the js I'm using, I've try submitting with a timeout and it's working.
at the end my issue is not there, it appear that when I'm submit the form, the 3 php variables push the value of the previous input entry.
I don't know if I'm clear with my explanation...
<script type="text/javascript">
function submitform()
{
//document.getElementById("weeklysheet");
var form = document.getElementById("weeklysheet")
form.submit();
}
function submit()
{
if (document.getElementById("weeklysheet")) {
setTimeout("submitform()", 5000); // set timout
}
return false;
}
</script>
(sorry if it's a long explanation)
I'm coming back with my solution... in case that can help anyone.
so the idea it's to have a table that display a list of employees where you can input the days worked, holidays, sick. Then do the sum of each and calculate the gross depending on a wages frequency (i.e: Weekly, 4 Weekly or Monthly).
Because the user won't complete the all form at once, I needed to make the submission automatic for all inputs at all the time of the current week.
this is the JS:
<script type="text/javascript">
function grab<?=$empnum?>(){
// Monday
var mon<?=$empnum?> = document.getElementById('mon<?=$empnum?>').value;
if ((mon<?=$empnum?> == "h" || mon<?=$empnum?> == "H")){
var Hmon<?=$empnum?> = 1;
var Wmon<?=$empnum?> = 0;
var Smon<?=$empnum?> = 0;
}
else if((mon<?=$empnum?> == "w" || mon<?=$empnum?> == "W")){
var Wmon<?=$empnum?> = 1;
var Hmon<?=$empnum?> = 0;
var Smon<?=$empnum?> = 0;
}
else if((mon<?=$empnum?> == "s" || mon<?=$empnum?> == "S")){
var Smon<?=$empnum?> = 1;
var Hmon<?=$empnum?> = 0;
var Wmon<?=$empnum?> = 0;
}
else{
var Smon<?=$empnum?> = 0;
var Hmon<?=$empnum?> = 0;
var Wmon<?=$empnum?> = 0;
var Xmon<?=$empnum?> = 0;
}
// Tuesday
var tue<?=$empnum?> = document.getElementById('tue<?=$empnum?>').value;
if ((tue<?=$empnum?> == "h" || tue<?=$empnum?> == "H")){
var Htue<?=$empnum?> = 1;
var Wtue<?=$empnum?> = 0;
var Stue<?=$empnum?> = 0;
}
else if((tue<?=$empnum?> == "w" || tue<?=$empnum?> == "W")){
var Wtue<?=$empnum?> = 1;
var Htue<?=$empnum?> = 0;
var Stue<?=$empnum?> = 0;
}
else if((tue<?=$empnum?> == "s" || tue<?=$empnum?> == "S")){
var Stue<?=$empnum?> = 1;
var Htue<?=$empnum?> = 0;
var Wtue<?=$empnum?> = 0;
}
else{
var Stue<?=$empnum?> = 0;
var Htue<?=$empnum?> = 0;
var Wtue<?=$empnum?> = 0;
}
// Wednesday
var wed<?=$empnum?> = document.getElementById('wed<?=$empnum?>').value;
if ((wed<?=$empnum?> == "h" || wed<?=$empnum?> == "H")){
var Hwed<?=$empnum?> = 1;
var Wwed<?=$empnum?> = 0;
var Swed<?=$empnum?> = 0;
}
else if((wed<?=$empnum?> == "w" || wed<?=$empnum?> == "W")){
var Wwed<?=$empnum?> = 1;
var Hwed<?=$empnum?> = 0;
var Swed<?=$empnum?> = 0;
}
else if((wed<?=$empnum?> == "s" || wed<?=$empnum?> == "S")){
var Swed<?=$empnum?> = 1;
var Hwed<?=$empnum?> = 0;
var Wwed<?=$empnum?> = 0;
}
else{
var Swed<?=$empnum?> = 0;
var Hwed<?=$empnum?> = 0;
var Wwed<?=$empnum?> = 0;
}
// Thurday
var thu<?=$empnum?> = document.getElementById('thu<?=$empnum?>').value;
if ((thu<?=$empnum?> == "h" || thu<?=$empnum?> == "H")){
var Hthu<?=$empnum?> = 1;
var Wthu<?=$empnum?> = 0;
var Sthu<?=$empnum?> = 0;
}
else if((thu<?=$empnum?> == "w" || thu<?=$empnum?> == "W")){
var Wthu<?=$empnum?> = 1;
var Hthu<?=$empnum?> = 0;
var Sthu<?=$empnum?> = 0;
}
else if((thu<?=$empnum?> == "s" || thu<?=$empnum?> == "S")){
var Sthu<?=$empnum?> = 1;
var Hthu<?=$empnum?> = 0;
var Wthu<?=$empnum?> = 0;
}
else{
var Sthu<?=$empnum?> = 0;
var Hthu<?=$empnum?> = 0;
var Wthu<?=$empnum?> = 0;
}
// Friday
var fri<?=$empnum?> = document.getElementById('fri<?=$empnum?>').value;
if ((fri<?=$empnum?> == "h" || fri<?=$empnum?> == "H")){
var Hfri<?=$empnum?> = 1;
var Wfri<?=$empnum?> = 0;
var Sfri<?=$empnum?> = 0;
}
else if((fri<?=$empnum?> == "w" || fri<?=$empnum?> == "W")){
var Wfri<?=$empnum?> = 1;
var Hfri<?=$empnum?> = 0;
var Sfri<?=$empnum?> = 0;
}
else if((fri<?=$empnum?> == "s" || fri<?=$empnum?> == "S")){
var Sfri<?=$empnum?> = 1;
var Hfri<?=$empnum?> = 0;
var Wfri<?=$empnum?> = 0;
}
else{
var Sfri<?=$empnum?> = 0;
var Hfri<?=$empnum?> = 0;
var Wfri<?=$empnum?> = 0;
}
// Saturday
var sat<?=$empnum?> = document.getElementById('sat<?=$empnum?>').value;
if ((sat<?=$empnum?> == "h" || sat<?=$empnum?> == "H")){
var Hsat<?=$empnum?> = 1;
var Wsat<?=$empnum?> = 0;
var Ssat<?=$empnum?> = 0;
}
else if((sat<?=$empnum?> == "w" || sat<?=$empnum?> == "W")){
var Wsat<?=$empnum?> = 1;
var Hsat<?=$empnum?> = 0;
var Ssat<?=$empnum?> = 0;
}
else if((sat<?=$empnum?> == "s" || sat<?=$empnum?> == "S")){
var Ssat<?=$empnum?> = 1;
var Hsat<?=$empnum?> = 0;
var Wsat<?=$empnum?> = 0;
}
else{
var Ssat<?=$empnum?> = 0;
var Hsat<?=$empnum?> = 0;
var Wsat<?=$empnum?> = 0;
}
// Sunday
var sun<?=$empnum?> = document.getElementById('sun<?=$empnum?>').value;
if ((sun<?=$empnum?> == "h" || sun<?=$empnum?> == "H")){
var Hsun<?=$empnum?> = 1;
var Wsun<?=$empnum?> = 0;
var Ssun<?=$empnum?> = 0;
}
else if((sun<?=$empnum?> == "w" || sun<?=$empnum?> == "W")){
var Wsun<?=$empnum?> = 1;
var Hsun<?=$empnum?> = 0;
var Ssun<?=$empnum?> = 0;
}
else if((sun<?=$empnum?> == "s" || sun<?=$empnum?> == "S")){
var Ssun<?=$empnum?> = 1;
var Hsun<?=$empnum?> = 0;
var Wsun<?=$empnum?> = 0;
}
else{
var Ssun<?=$empnum?> = 0;
var Hsun<?=$empnum?> = 0;
var Wsun<?=$empnum?> = 0;
}
var W<?=$empnum?> = Wmon<?=$empnum?>*1+Wtue<?=$empnum?>*1+Wwed<?=$empnum?>*1+Wthu<?=$empnum?>*1+Wfri<?=$empnum?>*1+Wsat<?=$empnum?>*1+Wsun<?=$empnum?>*1;
var H<?=$empnum?> = Hmon<?=$empnum?>*1+Htue<?=$empnum?>*1+Hwed<?=$empnum?>*1+Hthu<?=$empnum?>*1+Hfri<?=$empnum?>*1+Hsat<?=$empnum?>*1+Hsun<?=$empnum?>*1;
var S<?=$empnum?> = Smon<?=$empnum?>*1+Stue<?=$empnum?>*1+Swed<?=$empnum?>*1+Sthu<?=$empnum?>*1+Sfri<?=$empnum?>*1+Ssat<?=$empnum?>*1+Ssun<?=$empnum?>*1;
var totals<?=$empnum?> = document.getElementById('totalhrs<?=$empnum?>').value = W<?=$empnum?>;
var holiday<?=$empnum?> = document.getElementById('holihrs<?=$empnum?>').value = H<?=$empnum?>;
var sick<?=$empnum?> = document.getElementById('sickdays<?=$empnum?>').value = S<?=$empnum?>;
var wage<?=$empnum?> = document.getElementById('wagefreq<?=$empnum?>').value;
if(wage<?=$empnum?> == 'Weekly'){
document.getElementById('gross<?=$empnum?>').value = <?=$empsalarywage?>;
}
else if(wage<?=$empnum?> == '4 Weekly'){
document.getElementById('gross<?=$empnum?>').value = (<?=$empsalarywage?> / 4);
}
else if(wage<?=$empnum?> == 'Monthly'){
document.getElementById('gross<?=$empnum?>').value = ((<?=$empsalarywage?> * 12) / 52);
}
document.getElementById('weeklysheet<?=$empnum?>').submit('save<?=$empnum?>');
}
</script>
this the form:
<form id="weeklysheet<?=$empnum?>" name="weeklysheet" method="post" action="salary-function.php" >
<tbody>
<tr style="line-height:0px;">
<td class="large">
<p class="employee_name"><?=$fullname?></p>
</td>
<td class="small">
<input name="mon" id="mon<?=$empnum?>" type="text" class="days_input" maxlength="1" value="<?php echo $mon?>"onchange="grab<?=$empnum?>()"/>
</td>
<td class="small">
<input name="tue" id="tue<?=$empnum?>" type="text" class="days_input" maxlength="1" value="<?php echo $tue?>"onchange="grab<?=$empnum?>()"/>
</td>
<td class="small">
<input name="wed" id="wed<?=$empnum?>" type="text" class="days_input" maxlength="1" value="<?php echo $wed?>"onchange="grab<?=$empnum?>()"/>
</td>
<td class="small">
<input name="thu" id="thu<?=$empnum?>" type="text" class="days_input" maxlength="1" value="<?php echo $thu?>"onchange="grab<?=$empnum?>()"/>
</td>
<td class="small">
<input name="fri" id="fri<?=$empnum?>" type="text" class="days_input" maxlength="1" value="<?php echo $fri?>"onchange="grab<?=$empnum?>()"/>
</td>
<td class="small">
<input name="sat" id="sat<?=$empnum?>" type="text" class="days_input" maxlength="1" value="<?php echo $sat?>"onchange="grab<?=$empnum?>()"/>
</td>
<td class="small">
<input name="sun" id="sun<?=$empnum?>" type="text" class="days_input" maxlength="1" value="<?php echo $sun?>"onchange="grab<?=$empnum?>()"/>
</td >
<td class="small">
<input name="totalhrs" id="totalhrs<?=$empnum?>" type="text" class="cumul_week_input" readonly value="<?php echo $totalhrs?>"/>
</td>
<td class="small">
<input name="holihrs" id="holihrs<?=$empnum?>" type="text" class="cumul_week_input" readonly value="<?php echo $holihrs?>"/>
</td>
<td class="small">
<input name="sickdays" id="sickdays<?=$empnum?>" type="text" class="cumul_week_input" readonly value="<?php echo $sickdays?>"/>
</td>
<td class="small">
<input name="gross" id="gross<?=$empnum?>" type="text" class="cumul_week_input" readonly value="<?php echo $gross?>"/>
</td>
<td>
<input type="submit"name="save" id="save<?=$empnum?>" value="Confirm" style="display:none"/>
<input type="hidden"name="enddate" value="<?php echo $data['currentWeekStart']; ?>"/>
<input type="hidden"name="wagefreq"id="wagefreq<?=$empnum?>" value="<?=$wagefreq?>"/>
</td>
</tr>
</tbody>
</form>
that's something that worked like I want, but if anyone see anything that could be done in a better way, I would really apreciate any corrections...
thank's

Categories