radion button selection based on input value [closed] - javascript

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

Related

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

How to use JQUERY to select a radio button [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 6 years ago.
Improve this question
I intend to write a piece of code to select one option in a radio button. I used the following code which is saw being used to select a dropdown. I modified it and used it but its not working. Could you please point out my error?
$("div.classradio radio").val("Male");
this is the code I used but it doesn't work.
$("div.classradio radio").prop("checked", true)
For versions of jQuery prior to 1.6, use:
$("div.classradio radio").attr('checked', 'checked');
Why you want do this with jQuery? It's very simple with HTML:
<form>
<input type="radio" name="gender" value="male" checked> Male<br>
<input type="radio" name="gender" value="female"> Female<br>
<input type="radio" name="gender" value="other"> Other
</form>
With jQuery you can do it like this:
$('input:radio[name=gender]')[1].checked = true;
The Number in the brackets indicates the radio button. Attention: jQuery starts counting at 0.
Please set the attribute of the input element by selector
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
<script>
$(document).ready(function () {
$('#FeMale').attr('checked',true);
});
</script>
</head>
<body>
<div class="container-fluid">
<input type="radio" name="Gender" value="Male" id="Male"/>Male
<input type="radio" name="Gender" value="FeMale" id="FeMale"/>Female
</div>
</body>
</html>
$("div.classradio radio").val("Male")
This code mean find the element with tag which is child of the div with class "classradio"
<div class="classradio">
<radio></radio>
</div>

HTML Select Box To Check Specific Options [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I've been lurking for a while, and finally need to ask a question!
I'm testing a select form as follows:
<form id='list'><br>
1<input type='checkbox' value='1' />
2<input type='checkbox' value='2' />
3<input type='checkbox' value='3' />
4<input type='checkbox' value='4' />
5<input type='checkbox' value='5' />
CheckThese<input type='checkbox' name='checkthese' onclick='checkThese()'><br>
</form>
And corresponding JavaScript as:
<script language='JavaScript'>
function checkThese () {
var values = ['1', '2', '4', '5'];
$("#list").find('[value=' + values.join('], [value=') + ']').prop("checked", true);
}
</script>
For some reason, when I check "CheckThese" checkbox in the form, it doesn't select option 1, 2, 4, and 5..
Can someone please help me get it work?
Thank you very much!
Your code works provided you link jquery src??
add the following to your code : (using google cdn)
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>

How to filter among a number of radio button for a radio button with particular label [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 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.

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);
});

Categories

Resources