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);
});
Related
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
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I use this code to make simple form function with javascript, but doesn't work correctly.
(function(){
var o=document.getElementById('formsz');
o.getElementsByTagName('form')[0].onsubmit=function(){
if(this.version.value == "show"){
alert("show")
}else{
alert("hide")
}
return false
}})();
<div id="formz">
<form action='#'>
<input type="radio" name="version" id="x64" value="show">Show<br/>
<input type="radio" name="version" id="x32" value="hide">Hide<br/>
<button type='submit'>Login</button>
</form>
</div>
Whats wrong?? Why it doesn't work ??? Please help,,,
'formzs' !== 'formz' - .getElementById is finding nothing because you've passed the wrong ID in.
Try using your developer console next time, the error is pretty obvious.
(function(){
var o = document.getElementById('formz');
o.getElementsByTagName('form')[0].onsubmit=function(){
if(this.version.value == "show"){
alert("show")
}else{
alert("hide")
}
return false
};
})();
<div id="formz">
<form action='#'>
<input type="radio" name="version" id="x64" value="show">Show<br/>
<input type="radio" name="version" id="x32" value="hide">Hide<br/>
<button type='submit'>Login</button>
</form>
</div>
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/
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 9 years ago.
Improve this question
i have a text field , where i input the value to filter ....
<input type="text" name="filter" id="filter">
<input type="radio" name="item" id="item" value="1">apple
<input type="radio" name="item" id="item" value="2">banana
<input type="radio" name="item" id="item" value="3">grapes
<input type="radio" name="item" id="item" value="4">mango
<input type="radio" name="item" id="item" value="5">orange
<input type="radio" name="item" id="item" value="6">pineapple
if i input apple in text field, only radio button with apple has text value should appear , rest must hide . Is der any way to do that ?
Check out the jquery selectors page:
"Attribute Contains Selector [name*="value"]"
var name2lookFor = $('#filter').val();
var $matchingElements = $('input[type="radio"]').filter('[name*="'+name2lookFor +'"]');
There are a lot of other selectors, just find the one you need. You might need a combination to make a bit more custom search, but this should put you in the right track.
Offtopic: An id must be unique, you cant call them the same in the ID attribute.
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 9 years ago.
Improve this question
I have two radio buttons. Male and Female.
I want to select any one of these radio button based on input given via $_POST from
another page. If the input is 'male' then respective radio button should be cheked.
Any one pl help me to achieve this.
You can do in this way
$checked = $_POST['gender'];
<input type="radio" value="male" <?php if($checked=="male"){echo "checked"}; ?> > Male
<input type="radio" value="female" <?php if($checked=="female"){echo "checked"}; ?> > Female
Here is the sample code for this.
<input type="radio" name="gender" value="male" <?php if(isste($_POST['data']) && $_POST['data'] == 'male') { echo 'checked="checked"'; } ?> /> Male
<input type="radio" name="gender" value="female" <?php if(isste($_POST['data']) && $_POST['data'] == 'female') { echo 'checked="checked"'; } ?> /> Female