hi currently i have developed my own website named www.eyeview.com. i want to update the hidden amount to my add product by clicking radio buttons. i have a five radio buttons with values of 100$ 150$ 200£ 175$ and 87$ but hidden amount value is 222
var totalAmount = 222.00; //Set from the database
function updateAmount(var additionalCost)
{
document.getElementById("finalamount").innerHTML = totalAmount + additionalCost;
}
var $amount=
(‘#repair_total_amount’).html(“Total <span class="repair-finalamount-txt">£ ”+ total_amount+”</span>”);
`$amount.text('£ 100');`
`$amount.text('£ 150');`
`$amount.text('£ 175');
`$amount.text('£ 87');
`$amount.text('£ 200');
i want to display the value on the product palce ie basket item. there is no response in my page ie nothing action after i clicked.
give me a correct code plz for updating the amount also i wanna to need the function for update
thanks in adv
Based on the fact you have tagged this post with jQuery, here is a clean jQuery solution that will work for you (just ensure you include the library of course):
<script type="text/javascript">
var startAmount = 222.0;
var finalAmount = 0;
$(document).ready(function() {
$('.c').click(function() {
$('.c:checked').each(function() {
finalAmount = startAmount + parseFloat($(this).val());
});
$('#finalAmount').html('Final Amount: $' + finalAmount);
});
});
</script>
<input name="cost" type="radio" value="100" class="c" /> 100$
<input name="cost" type="radio" value="150" class="c" /> 150$
<input name="cost" type="radio" value="200" class="c" /> 200$
<input name="cost" type="radio" value="175" class="c" /> 175$
<input name="cost" type="radio" value="87" class="c" /> 87$
<br />
<span id="finalAmount">Final Amount: $0</span>
document.getElementById('BUTTON-ID-HERE').onclick = function(){ updateAmount('VALUE HERE') };
Should be sufficent. Hope that helps.
Related
my Code not working Exactly as I need, 2 pages php and 1 jquery file to get the data by jquery Ajax.
First Page name catfd.php :
<input type="checkbox" value="2" class="catcf"> catfd2 <br />
<input type="checkbox" value="35" class="catcf"> catfd35 <br />
<input type="checkbox" value="22" class="catcf"> catfd22 <br />
<input type="checkbox" value="133" class="catcf"> catfd133 <br />
<input type="checkbox" value="28" class="catcf"> catfd28 <br />
<input type="checkbox" value="33" class="catcf"> catfd33 <br />
<input type="checkbox" value="55" class="catcf"> catfd55 <br />
<input type="checkbox" value="44" class="catcf"> catfd44 <br />
and the second page name getvalue.php
this page it's given me the right answer if var '$catcfid' is Exactly one I choose from input filed in catfd.php ( i think my problem with Jquery ajax
if(isset($_POST['catcf'])){
$catcfid= $_POST['catcf'];
$sql = 'SELECT * FROM tablename where cat_id = '.$catcfid.' order by p_id asc';
$catandproid = $wpdb->get_results($sql);
foreach($catandproid as $key){
echo $key->title;
}
}
this is the jquery ajax file
$(document).ready(function(){
$(".catcf").on('click', function() {
if ($('input.catcf').is(':checked')) {
var catcf = Number($(this).val());
$(".catcf").val(catcf);
$.ajax({
url: 'getvalue.php',
type: 'post',
data: {catcf:catcf},
beforeSend:function(){
$(".main-area-courses-continer").html("Looding....");
},
success: function(response){
// Setting little delay while displaying new content
setTimeout(function() {
// appending posts after last post with class="post"
$(".main-area-courses-continer:last").after(response).show().fadeIn("slow");
}, 2000);
}
});
}
});
});
the code is working but the result gives to me is repeating the first checkbox value I choose its mean jquery didn't change the value of class="catcf" because there unic value for each class. and I will use multiple choices from the checkbox.
i want use this checkbox to get different result from database .
Your problem is the following line:
$(".catcf").val(catcf);
What's happening here is that you select all of your checkboxes ($(".catcf")) and then change their value attribute to the value of the clicked checkbox. Remove this line and it should work as expected.
How to get value from checkbox or radio button immediately after clicking on it and write it in textfield without using reset or submit button?
<input type="checkbox" name="age" value="21-29">21-29 <input type="text" name="yourAge" value="">
You can do like this with jQuery click function More Detail Here
<input type="checkbox" name="age" value="21-29" id="age">21-29
<input type="text" name="yourAge" value="" id="yourAge">
JQuery
$("#age").click(function () {
$("#yourAge").val($("#age").val());
});
Fiddle
#Shehary is on point but there is always room for more.
JS
<script>
var changeInput = function (val){
var input = document.getElementById("age");
input.value = val;
}
</script>
HTML
<input type="checkbox" name="age" value="21-29" onclick='changeInput(this.value);' >21-29
<input type="text" name="yourAge" value="" id="age">
Pen
I know this is old, and my code may not be great, but I like to use this.
<?php
$get= "?checked";
$checked= "";
if(isset($_GET['checked'])){
$get= "";
$checked= "checked";
}
?>
<a href="waiting_in_db.php<?=$get?>">
<input type="checkbox" <?=$checked?> >
</a>
But I prefer using CSS and links without the checkbox.
I'm Prasath and I'm new to AJAX. I am working on seat layout project, I find difficult to get seat fare and seat number at same time. Kindly some one help me to solve my problem. Here is my code
<div id="mydiv">
<input type="checkbox" name="seat1" id="A1" value="250" />
<br />
<input type="checkbox" name="seat2" id="A2" value="250" />
<br />
<input type="checkbox" name="seat3" id="A3" value="300" />
<br />
<input type="checkbox" name="seat4" id="SL1" value="250" />
<br />
<input type="checkbox" name="seat5 " id="SL2"
value="250" />
<br />
<input type="checkbox" name="seat6" id="SL3" value="300" />
<br />
<input type="checkbox" name="seat7 " id="SL4" value="300" />
<textarea id="seats"></textarea>
<textarea id="total_amount"></textarea>
</div>
I want result as
if checkbox "Seatl, seat3 and seat7" are checked I want result as
<textarea id="seats">A1,A3,SL4</textarea>
<textarea id="total_amount">750</textarea>
Kindly help me to solve this.
Thanks in advance.
You can do it just with plain javascript (no need of jQuery):
function myAudis(){
var inputs = document.getElementById("mydiv").getElementsByTagName("input");
var seats=[], total_amount=0, c=0;
for(var i=0;i<inputs.length;i++){
if(inputs[i].type!="checkbox"){continue;}
if(inputs[i].checked){seats[c++]=inputs[i].id; total_amount+=parseInt(inputs[i].value);}
}
document.getElementById("seats").value=seats;
document.getElementById("total_amount").value=total_amount;
}
You can call it like this:
<button type="button" onclick="myAudis()">Calculate</button>
Hope it helps..
$(document).ready(function(e) {
var ids = "";
$(':checkbox').bind('change',function(){
var th = $(this), id = th.attr('id');
//alert(th);
if(th.is(':checked')){
ids = ids+id+",";
$('#seats').val(ids);
}
else
{
ids = ids.replace(id+",","");
$('#seats').val(ids);
}
});
});
First add a common class for the checkbox like seatsNos
Add this in your on submit function or if event want it in every checkbox click add add check checked event
var total = 0;
var textarea = '';
$('.seatsNos:checked').each(function () {
var e = $(this);
var textarea = ',' + e.attr('id');
total = total + e.val();
});
$('#seats').val(textarea );
Note : Jquery needed
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Combine $_GET variables before Submit
I am not really sure if this is possible but here is the problem I cant figure out.
I need a way to have two boxes with a price min and max and a button that send the user to a link like this. where A is min price and B is max price.
End result Link.
domain/index.php?a=price_range_A_B
I can not use a from but i can use Input fields. Any ideas?
You will need to do this with javascript. In the "Submit" button/link/whatever click action, fetch the values of the fields and construct the url. Then either send the browser there, or do an ajax request, depending on your needs.
eg.
<script>
function doSubmit() {
var fieldA = document.getElementById('fieldA'),
fieldB = document.getElementById('fieldB'),
valA = fieldA.value,
valB = fieldB.value,
url = "/index.php?a=price_range_" + valA + "_" + valB;
window.location = url;
}
</script>
<input id="fieldA" />
<input id="fieldB" />
<input type="button" onclick="doSubmit();" />
use this function onclick of button
function value_change(){
var a=document.getElementById('box1').value();
var b=document.getElementById('box2').value();
document.getElementById('linkdiv').innerHTML()="domain/index.php?a=price_range_"+A+"_"+B;
}
where box1 and box2 are ids of max and min price respectively and linkdiv is id od di that shows the link
<input id="one" type="text" />
<input id="two" type="text" />
<input id="go" type="button" value="button"/>
$("#go").click(function(){
window.location = "http://google.com/a=price_range_" + $("#one").val() + '_' + $("#two").val();
});
http://jsfiddle.net/kTUu5/
Try this code,
HTML
<div>
Max: <input type="textbox" id="max" name="max" value="" />
<br />
Min: <input type="textbox" id="min" name="min" value="" />
<br />
<input type="button" name="btn" value="Submit" onclick="sendData()"/>
</div>
Javascript
function sendData(){
var max = document.getElementById('max').value;
var min = document.getElementById('min').value;
if(!max || !min){
alert('Enter max and min value');
return false;
}
window.location = "http://domain/index.php?a=price_range_"+min+"_"+max;
}
Demo: http://jsfiddle.net/muthkum/FhY5a/
Yes. You can do it if you can use any client side scripting Like javascript or 'Jquery'. You have to bind a click event fubnction on that Submit button. So once you click on that button it will call a function which take the value of those inputbox and prepared a url and send you to that location.
Example:
<input type="text" name="minPrice" id="min" value="" />
<input type="text" name="maxPrice" id="max" value="" />
<button type="button" name="Submit" onClick="doSubmit()">Submit</button>
Now Your doSubmit() function.
function doSubmit(){
var minPrice=document.getElementById('min').value;
var maxPrice=document.getElementById('max').value;
var location='domain/index.php?a=price_range_'+minPrice+'_'+maxprice+'';
window.location=location;
}
Now on the index page you can easily explode $_REQUEST['a'] variable like this way
$var=$_REQUEST['a'];
$explodedVar=explode('_',$var);
//print_r($explodedVar);
$minPrice=$explodedVar[2];
$maxPrice=$explodedvar[3];
hi i have the confusion with my jquery. i have d 4 button to update the value.
let me explain it clearly
this four buttons are select method for an amount. my project is based upon the labtop and iphones. by the shopping cart customer choose the product and then they have to select the button(any 4 in those buttons)
if customer cart amount is 50£ in the sense then they need to choose the radio button if customer select 2 button in the sense the 2nd button amount must add with shopping cart and then displayed like a 55£
if i click the button there is no change when mouse arrow is on the button i could see the error page in below. what action i need to put for the changes i mean the action for the radio button.
<form method="post" form name="make_payment_frm"
action="module/make-payment-module.php"
onsubmit="return show_make_payment_validation();" >
<input type="radio" name="rmr" id="payment1" value="30"
onclick="updatepayment(this.value)" />
<input type="radio" name="rmr" id="payment2" value="39"
onclick="updatepayment(this.value)" />
<input type="radio" name="rmr" id="payment3" value="42"
onclick="updatepayment(this.value)" />
<input type="radio" name="rmr" id="payment4" value="45"
onclick="updatepayment(this.value)" />
<input type="hidden" name="totalamount" id="totalamount"
value="<?php echo get_total_amount(); ?>" />
$(document).ready(function(){
$("input[name='rmr']").click(function() {
updatePayment($(this).val());
if (!!$(this).attr("checked") == true) {
$("#finalamount").html(
parseInt($("#totalamount").val(), 10) * parseInt($(this).val(), 10));
}
});
}
var totalAmount = 50.0; //Set from the database
function updateAmount(var additionalCost)
{
document.getElementById("finalamount").innerHTML = totalAmount
+ additionalCost;
}
document.getElementById('payment1').onclick = function(){
updateAmount('30')
};
document.getElementById('payment2').onclick = function(){
updateAmount('39')
};
document.getElementById('payment3').onclick = function(){
updateAmount('42')
};
document.getElementById('payment4').onclick = function(){
updateAmount('45')
};
guys can any one tell me the good idea for the radio button works properly. that amount must add with that payment cart and then display.is there any thing wrong in my code. plz help me.
thanks and regards
magna
``
function updateAmount(var additionalCost)
remove the var there.