Updating prices based on options [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
So I am making this billing system where a user is able to configure a VPS. As seen in websites like Dell, the price of the server updates as you choose a specific option. I don't want the user to have to press a button "Refresh" every time they want to see the price of the new VPS. I have no idea how to do this, I tried to do some research and the only thing I found that was remotely close to this was things like Comet. I'm guessing that JavaScript should detect the change and change the overall price. Any suggestions/ideas?

Guess you wanna use JavaScript to achieve this.
<form action="">
<ul>
<li><label><input type="checkbox" value="1"> One</label></li>
<li><label><input type="checkbox" value="2"> Two</label></li>
<li><label><input type="checkbox" value="3"> Three</label></li>
<li><label><input type="checkbox" value="4"> Four</label></li>
<li><label><input type="checkbox" value="5"> Five</label></li>
</ul>
</form>
<p>Your total cost is <span>0</span> $.</p>
And a magic of JavaScript...
$(document).ready(function(){
$("input").click(function(){
val = 0;
$("input:checked").each(function(){
val += parseInt($(this).val());
});
$("span").text(val);
});
});
Fiddle: http://jsfiddle.net/praveenscience/q3XbZ/

Related

If checkbox "A" and "C" is checked make checkbox "B" checked to [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Hi there i have a problem and dont know if there's a nice solution to do that.
<input type="checkbox" name="a" value="a">a<br>
<input type="checkbox" name="b" value="b">b<br>
<input type="checkbox" name="c" value="c">c<br>
<input type="checkbox" name="d" value="c">d<br>
<input type="checkbox" name="e" value="c">e<br>
I like to make it work more as a "range" so if a user click "a" and then "d" everything between that will be selected to.
I can make if statements with all the scenarios but maybe there's a better way to do that?
thanks
This is really simple with jQuery - use prevAll like so:
$('input[type="checkbox"]').on("change", function() {
if ($(this).is(":checked")) this.prevAll('input[type="checkbox"]').prop("checked", true);
});

Multiple checkboxes to variable logic [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am looking to create a simple page using HTML and (probably) PHP or JQuery. The page should allow for multiple checkbox selection, and give a variable a value based on which boxes are checked. This can be on submit or can render live on the page.
i.e.
Checkbox 1
Checkbox 2
Checkbox 3
If checkbox 1 is checked, variable = X
If checkbox 1 & 2 are checked, variable = Y
If no checkboxes are checked, variable = Z
What is the best way to approach doing this?
The best way would be using Javascript (because it'd be done live) but if you are doing this with PHP. The form would be something like
<form action='phplogic.php' method='post>
<input type="checkbox" name="checkbox1" value="Yes" />
<input type="checkbox" name="checkbox2" value="Yes" />
<input type="checkbox" name="checkbox3" value="Yes" />
<input type="submit" name="formSubmit" value="Submit" />
</form>
phplogic would would look like this
<?php
if(isset($_POST[checkbox1']) && (isset($_POST['checkbox2'])) {
$variable = 'Y';
} else (isset($_POST[checkbox1'])) {
$variable = 'X';
} else {
$variable = 'Z';
}
Although this doesn't address if checkbox 2 alone is checked but you get the point. You can do something very similar with javascript. https://www.w3schools.com/jsref/prop_checkbox_value.asp

Different ways to disable radio button [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
What are the different ways to disable a radio button.
I tried the example below but not working in my system with my environment set up. Its working if I am trying on notepad without environment. Is there any other ways?
var status = 'A';
$("input[type=radio][value=" + status + "]").attr("disabled",true);
I was able to just use disabled in HTML find your UPDATED CODE
<div id="cosProfile">CoS Profile</div>
<span class="icon-information"></span>
<div class="form-field" data-radio id="cosRadioBtns">
<span id="radio_prdefined"><input type="radio" name="CosProfile" data-radio
value="predefined" checked="checked" disabled/></span>
<label id="cos_predefined">Predefined Profile</label>
<span id="radio_custom"><input type="radio" name="CosProfile" data-radio
value="custom" disabled/></span>
<label id="cos_custom">Custom Profile</label>
</div>
Try this:
$("input[type=radio][value=" + status + "]").prop("disabled",true);

javascript with checkbox to count and hide/show [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
i need help to make one script
The script I'm trying to do is the following:
I have a page with multiple checkbox's corresponding products and they all have an associated value.
  then I have a variable that is the value I have in the account, and what I wanted to do with that as I start choosing products by clicking on the checkbox, javascript would have to count the value that has already been chosen and see how and lacking and hide all products that have a higher value or have available
<?php
$totalmoney = '50';
?>
<div class="tags">
<label><input type="checkbox" id="arts" value="20" /> Arts </label>
<label><input type="checkbox" id="computers" value="40" /> Computers </label>
<label><input type="checkbox" id="phone" value="15"/> Phone </label>
<label><input type="checkbox" id="video-games" value="5" /> Video Games </label>
</div>
Help me please, i need this to my work :S
Start with calculating the values of selected checkboxes with JS something like this:
var $inputs = $('#arts,#computers,#phone,#video-games');
$inputs.on('click', function (event) {
$checked = $inputs.is(':checked');
totalChecked = 0;
$checked.each(function () {
totalChecked += $(this).val();
});
});
Now you can easily check the rest:
var toBeSpend = totalmoney - totalChecked;
$inputs.not(':checked').each(function () {
$(this).toggle($(this).val() > toBeSpend);
});

the conditions radio button to another page after submit [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm making an application with PHP and javascript
There are 2 choices Yes and No.
When he chose NO option and submits, then going to the page "Thank You" and its data into the database. When selecting the YES option it will go to another page and its data into the database
<label class="radio inline"><input type="radio" name="choose" id="optionsRadios1" value="Yes">YES</label>
<label class="radio inline"><input type="radio" name="usia" id="optionsRadios2" value="No">NO</label>
<label class="control-label" for="">Nama</label>
<div class="controls"><input type="text" name="nama" ></div><input type="submit" name="submit" value="" class="btn next">
Try this,
function submitPage(url){
window.location.href=url;
}
$('input:radio').on('click',function(){
var url=this.value=='Yes' ? 'xyz.php' : 'abc.php';
submitPage(url); // or you can use ajax for post
});
Create a javascript function and fire it on the onclick event of the radiobutton passing the radio value in the parameter
And then in the function put condition for redirect and form submit
or you can call a ajax to insert data in the database

Categories

Resources