Condition when pressing radio button - javascript

How do i make my page do this in particular.
I have 2 choices LBC and PickUp,
If the user selects LBC, it would proceed to the next page to select payment options.
but if the user selects the PickUp radio option, it would be redirected immediately to the last page, since the payment option is no longer applicable.
I have this javascript function that enables a button, but other than that, i have no idea how do do it.
Redirecting the page depending on what radio button is pressed. If LBC no problem, if Pickup proceed to next page after payment page, so it would skip the payment page.
Please help thank you.
<form method="post" action="payment.php">
<?php
echo "<table><tr>";
$i = 0;
$qry="SELECT * FROM shipping";
$result= #mysql_query($qry);
while ($row=mysql_fetch_assoc($result)){
if ($i > 0 && $i % 3 == 0) {
echo "</tr><tr>";
}
echo "<td>";
?>
<table width="" cellpadding="3" cellspacing="0" border="0">
<tr class="row_submit">
<td height="250px" width="300px"><center><label>
<input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="$row[ship_name]") echo "checked";?> value="<?php echo $row['ship_name']; ?>">
<!--<img src="../paymentoptions/lbc.png" alt="LBC" class="picture" width="245px" style="margin:10px"/></label></td> -->
<?php echo '<img src="data:image/jpeg;base64,'.base64_encode( $row['ship_pic'] ).'" height="215px" width="245px" style="margin:10px"/>'; ?>
</tr>
<tr class="row_submit">
<td height="130px" width="300px"><p><?php echo $row['ship_desc']; ?><p></td>
<tr>
<td>
<div id='price'> Additional ₱ <?php echo $row['ship_price']; ?></div></td></tr>
</table>
<?php
echo "</td>";
$i++;
}
echo "</tr></table>";
?>
<br>
<table>
<tr>
<td><input type="button" value="View Shopping Cart" onclick="window.location='shoppingcart.php'"></td>
<td><input type="submit" disabled="disabled" name="next" value="Proceed to Payment" /></td>
</tr>
</table>
</form>

if($_POST['radio_button_name']['LBC']){
header('location:lbc_paymentpage.php');
}else{
header('location:pickuppage.php');
}

Related

How to calculate the rest of the inputs

I have a table and I am calculating the difference of hours but only first row of the table calculates me. and I have a method where created a new table is if the date is different
$(document).ready(function() {
getHrs();
});
function getHrs()
{
hstart=$('#horaInicio').val();
hend=$('#horaTermino').val();
hr1 = (hstart).split(":");
hr2 = (hend).split(":");
hrstart=(hr1[0]);
minstart=(hr1[1]);
hrend=(hr2[0]);
minend=(hr2[1]);
totalstart=parseInt((hrstart*60)) + parseInt(minstart);
totalend=parseInt(hrend*60) + parseInt(minend);
rsthr=(totalstart - totalend);
total=(rsthr / 60).toFixed(2);
$('#resultado').val(total);
}
here my table, I create a table for each different day.
<?php if ($seguimientos): ?>
<?php $fechas = array();
foreach ($seguimientos as $seguimiento) {
$fechas[$seguimiento-> fecha][] = $seguimiento;
}
?>
<?php foreach ($fechas as $fecha): ?>
<table class="table table-hover">
<thead>
<tr>
<th>Fecha</th>
<th>Orden</th>
</tr>
</thead>
<?php foreach ($fecha as $seguimiento): ?>
<tr>
<td>
<?php echo $seguimiento-> fecha; ?>
</td>
<td>
<?php echo $seguimiento-> horaInicio; ?>
<input type="hidden" id="horaInicio" value=" echo $seguimiento-> horaInicio;">
</td>
<td>
<?php echo $seguimiento-> horaFin; ?>
<input type="hidden" id="horaInicio" value=" echo $seguimiento-> horaFin;">
</td>
<td>
<input type="text" id="resultado" value="" readonly>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endforeach; ?>
<?php endif; ?>
could be the problem the ID must be unique
Yes, that is the problem, try not to use id's but rather data attributes, or classes.
like this: <input type="hidden" data-start="horaInicio" value=" echo $seguimiento-> horaInicio;">
Then your selector becomes: hstart=$('[data-start]').val(); And the same for the other input.

Live validation adding/updating data in a table php,ajax,javascript

Can help me to solve this?
I got a table and I have added 2 buttons to add or update information.
I wanna make a validation in the "description" field where **you can only write letters and less than 255 characters, and in the "name" field you can only write less than 50 characters. Anyway, I can not click on the button "save" or "add" respectively (the button is locked until everything is right).
Also, the page must show "In real time (before clicking the button) the errors in each field".
Here is my code, when adding new informationin the table:
<?php include('connect.php');
$error="";
if(isset($_POST['btnsave']))
{
$career_id=$_POST['carrera'];
$name=$_POST['txtname'];
$description=$_POST['txtdescription'];
$hourss=$_POST['txthours'];
if($_POST['txtid']=="0")
{
$a_sql=mysql_query("INSERT INTO subjects VALUES('','$career_id','$name','$description','$hourss')");
if($a_sql)
{
header("location:index.php");//
}
}else{
echo "Update";
}
}
$sqlm = mysql_query("SELECT * FROM careers");
$options = "";
while($result = mysql_fetch_array($sqlm)){
$options .= "<option value='".$result['id']."'>".$result['name']."</option>";
}
?>
<h2 align="center">ADD NEW SUBJECT</h2>
<form method="Post">
<table align="center">
<tr>
<td>Career:</td>
<td><select name='carrera'><?php echo $options; ?></select><input type="hidden" name="txtid" value="0" /></td>
</tr>
<tr>
<td>Name:</td>
<td><input type='text' name='txtname'/></td>
</tr>
<tr>
<td>Description:</td>
<td><input type='text' name='txtdesription'/></td>
</tr>
<tr>
<td>Hours:</td>
<td>
<select name='txthours'/>
<option <?php if($hourss=='1') echo 'selected' ; ?> value="2">2 (two)</option>
<option <?php if($hourss=='1') echo 'selected' ; ?> value="4">4 (our)</option>
<option <?php if($hourss=='1') echo 'selected' ; ?> value="6">6 (six)</option>
<option <?php if($hourss=='1') echo 'selected' ; ?> value="8">8 (eight)</option>
<option <?php if($hourss=='1') echo 'selected' ; ?> value="10">10 (ten)</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td><input type='submit' value=save name='btnsave'/></td>
</tr>
</table>
</form>
And the another code updates the information in the table:
<?php include('connect.php');
$error="";
if(isset($_GET['edit']))
{
$ident=$_GET['iden'];
$row=mysql_query("SELECT * FROM subjects WHERE id=$ident");
$st_row=mysql_fetch_array($row);
}
?>
<h2 align="center">UPDATE SUBJECT</h2>
<form method="Post" action=''>
<table align="center">
<tr>
<td>Career:</td>
<td><input type='text' name='txtcarreras_id' value="<?PHP echo $st_row['career'] ?>"/></td>
</tr>
<tr>
<td>Name:</td>
<td><input type='text' name='txtnombre' value="<?PHP echo $st_row['name'] ?>"/></td>
</tr>
<tr>
<td>Description:</td>
<td><input type='text' name='txtdescripcion' value="<?PHP echo $st_row['description'] ?>"/></td>
</tr>
<tr>
<td>Hours:</td>
<td><input type='text' name='txtcarga_horaria' value="<?PHP echo $st_row['hours'] ?>"/></td>
</tr>
<tr>
<td></td>
<td><input type='submit' value="save" name='btnsave'/></td>
</tr>
</table>
</form>
<?php
if(isset($_POST['btnsave']))
{
$career_id=$_POST['txtcarreras_id'];
$name=$_POST['txtnombre'];
$description=$_POST['txtdescripcion'];
$hours=$_POST['txtcarga_horaria'];
$a_sql=mysql_query("UPDATE materias SET career='$career_id', name='$name', description='$description', hours='$hours' WHERE id='$ident'");
if($a_sql)
{
header("location:index.php");
}
}
?>
I know, there are a lot of ways to solve this but i wanna the very best method!
Hope you can help me :)
Thanks!
You can do that using Javascript. With Jquery or another library it's even easier.
Using jQuery:
$('input[name=txtname]').keyup(function() {
if ($(this).val().length < 50) {
// Do Error stuff here
} else {
// Remove error stuff here
}
});
If you have jQuery and use the above keyup event handler, it should display as you type.

Get button value printed by php and process them via javascript

I have dynamic table where results from database are printed.
<table id="table" class="table datatable-responsive">
<thead>
<tr class="bg-teal">
<th>#</th>
<th>Datum & Vrijeme</th>
<th>Stavka</th>
<th><center>Izabrana količina</center></th>
<th><center><i class="icon-pencil"></i></center></th>
<th><center><i class="icon-bin"></i></center></th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
while ($r=$q->fetch()) {
$a = 0;
$a += 1;
$id = $r['Id'];
$datum = $r['Datum'];
$time = date("H:i:s",strtotime($datum));
$time2 = date("d/m/Y",strtotime($datum));
$stavka = $r['Stavka'];
$kolicina = $r['Kolicina'];
?>
<tr>
<td><?php echo $i; $i++; ?></td>
<td><?php echo $time2 .' & '.$time; ?></td>
<td><?php echo $stavka; ?></td>
<td class="nr"><center><?php echo $kolicina; ?></center></td>
<td><center><button type="button" value="<?php echo $id?>" name="izmjena" onClick="showDiv()"><i class="icon-pencil text-danger"></i></center></button>
</td>
<td><center><button type="submit" value="<?php echo $id ;?>" name="brisi" class="icon-bin text-danger"></button></center></td>
</tr>
<?php } ?>
</tbody>
<!--<a onClick="window.open('edit/korpa.php?id= <?=$r['Id']?>','E-cart','width=800,height=500,left=0,top=100,screenX=0,screenY=100,menubar=yes,scrollbars=yes')"> -->
</table>
In the table I have button for editing "Kolicina". Once I click on button in a row, It needs to open div.
In that div, I need to pass values and print them by using js. Once I do that, I need to save it in db by php
Once I click on button div below shows (it works).
<div class="col-lg-9" id="IzmjenaDiv" style="display:none;" >
<div class="panel panel-flat">
<table class="table table-bordered">
<tr>
<th class="">Količina</th>
<td class=""><input type="text" id="id" value="" class="form-control text-info border-info"></td>
<td class=""><input type="text" id="kolicina" name="kolicina" placeholder="Upišite novu količinu" class="form-control text-danger border-danger"></td>
<td class="">
<select class="form-control" id="mjera" name="mjera">
<option value="KG">KG </option>
<option value="KOM">KOM </option>
</select>
</td>
</tr>
</table><hr/>
<div class="pull-right">
<button type="button" class="btn btn-success btn-sm" onclick="savechanges()"> Snimi <i class="icon-play3 position-right"></i></button>
</div>
<br/><br/><br/>
</div>
</div>
I need to make script which willl get two values from row, one from button one from row "Kolicina". Then I need to print those values in div that shows on click.
I made script but it automatically closes div I want to open.
<script>
function showDiv() {
document.getElementById('IzmjenaDiv').style.display = "block";
var y = $(object).parent("center").parent("td").parent("tr").find(".nr center").text();
var x = $(object).attr("value");
window.location.href = "korpa.php?w1=" + x + "&w2=" + y;
}
</script>
Any advice is appreciated
Pass the reference of the TD tag as an argument in the showDiv() function. Change the HTML:
<td><center><button type="button" value="<?php echo $id?>" name="izmjena" onClick="showDiv(this)"><i class="icon-pencil text-danger"></i></center></button>
</td>
Javascript:
function showDiv(obj) {
document.getElementById('IzmjenaDiv').style.display = "block";
var id = $(obj).parent("center").parenrt("td").parent("tr").find(".nr center").text();
}

How to get the value of selected checkbox in jquery and assign it to a json array?

I have a problem, I have little understanding about jquery that's why I am having a hard time with my code. I have a pagination of products. And there are checkboxes on it. And my simple goal is to disable the products if the checkboxes are selected. But I can't do it in one form because I have already another process in my form which is delete products if selected. That's why I am planning to create a form action in my jquery and pass all the product id from my checkbox to a json array. But how can I do that?
Here's a bit of my code
<form action="<?php echo $delete; ?>" method="post" enctype="multipart/form-data" id="form">
<table class="list">
<thead>
<tr>
<td width="1" style="text-align: center;"><input type="checkbox" onclick="$('input[name*=\'selected\']').attr('checked', this.checked);" /></td>
<td class="left"><?php echo $column_name; ?></td>
<td class="right"><?php echo $column_sort_order; ?></td>
<td class="left"><?php echo $column_status; ?></td>
<td class="right"><?php echo $column_action; ?></td>
</tr>
</thead>
<tbody>
<?php if ($categories) { ?>
<?php foreach ($categories as $category) { ?>
<tr>
<td style="text-align: center;"><?php if ($category['selected']) { ?>
<input type="checkbox" name="selected[]" value="<?php echo $category['category_id']; ?>" checked="checked" />
<?php } else { ?>
<input type="checkbox" name="selected[]" value="<?php echo $category['category_id']; ?>" />
<?php } ?></td>
<td class="left"><?php echo $category['name']; ?></td>
<td class="right"><?php echo $category['sort_order']; ?></td>
<td class="right"><?php echo ($category['status'] == 1 ? 'Enable' : 'Disable'); ?></td>
<td class="right"><?php foreach ($category['action'] as $action) { ?>
[ <?php echo $action['text']; ?> ]
<?php } ?></td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td class="center" colspan="4"><?php echo $text_no_results; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</form>
<br />
<div align="right">
<select name="action_select">
<option value="enable">Enable Selected</option>
<option value="disable">Disable Selected</option>
</select>
<input type="button" class="button" id="update_status" value="Update Status" />
</div>
<br />
Here's my jquery sample
<script type="text/javascript">
$("#update_status").on('click', function(){
//how can I get the id of my checkboxes and assign it to a json array
//How can I create a form inside it?
});
</script>
That's all guys I hope you can understand my question. Thanks.
Otherwise you can use the below example code
<script>
$(document).ready(function()
{
$("input[type=checkbox]").click(function()
{
var categoryVals = [];
categoryVals.push('');
$('#Category_category :checked').each(function() {
categoryVals.push($(this).val());
});
$.ajax({
type:"POST",
url:"<?php echo $this->createUrl('ads/searchresult'); ?>", //url of the action page
data:{'category': categoryVals},
success : function(response){
//code to do somethng if its success
}
});
}
}
</script>
try
$('input[name="selected[]"]:checked').each(function() {
console.log(this.value);
});
for more info :- use jQuery to get values of selected checkboxes
Try
var values = $('.list input[name="selected[]"]:checked').map(function () {
return this.value;
}).get();

Get data from <td> on the same table row specified by row id and perform computation

I have an html table populated by data coming from a mysql database. This is the structure:
<table>
<?php
foreach($prods as $key=>$p){
?>
<tr class="row1" id="tr<?php echo $p['ProductID']?>">
<td id="pid<?php echo $p['ProductID']?>"><?php echo $p['ProductID']?></td>
<td id="pname<?php echo $p['ProductID']?>"><?php echo $p['ProductName'];?></td>
<td id="pdesc<?php echo $p['ProductID']?>"><?php echo $p['ProductDesc'];?></td>
<td id="pprice<?php echo $p['ProductID']?>"><?php echo $p['UnitPrice'];?></td>
<td><input type="checkbox" id="chk<?php echo $p['ProductID']?>" checked></td>
<td><input type="text" style="width:50px;" onkeyup="getall(this);" id="<?php echo $p['ProductID']?>"></td>
<td><input type="text" style="width:50px;" id="total<?php echo $p['ProductID']?>"> </td>
<span id="ttl" name="ttl"> 0.00</span>
</tr>
<?php
}
?>
</table>
I don't have issues populating the table, however I need to update the <span id="ttl"> value, every time the user changes the value of the <input type="text" style="width:50px;" onkeyup="getall(this);" id="<?php echo $p['ProductID']?>"></td>. I made a Javascript function but I fail doing what I want.
The value of the span should be the product of <td id="pprice<?php echo $p['ProductID']?>"><?php echo $p['UnitPrice'];?></td> and the quantity entered by the user at the textbox.
I will soon save these data back into the database once all fields are filled.
Not sure if this is used correctly. Just try something like:
<input type="text" style="width:50px;" onkeyup="getall('<?php echo $p['ProductID']?>');" id="<?php echo $p['ProductID']?>"></td>
And in your javascript function:
function getall(strId)
{
var tmpObj = document.getElementById(strId);
alert("reported id for testing: " + tmpObj.getAttribute("id"));
}
Try that.

Categories

Resources