Within my application I have a 3 steps registration form. In part one someone has
to select a package (member ship).
Here I need one group of radio buttons but because I am handeling 3 packages with each
2 options, with a lot of html between each 2 radio buttons I need to separate the
radio buttons and getting them one by one. the separate option for this is probably not
enough because it's not consistent with html and there can be a lot of html between.
Thanks! =)
You can do this using js hide-show
<script>
$(function(){
$("#package1").on(click,function(){
$("#p1").show();
});
$("#package2").on(click,function(){
$("#p2").show();
});
$("#package3").on(click,function(){
$("#p3").show();
});
});
</script>
<style>
.hidden {
display: none;
}
</style>
<input type="radio" name="package" id="package1" value="Package1">
<input type="radio" name="package" id="package2" value="Package2">
<input type="radio" name="package" id="package3" value="Package3">
<input class="hidden" type="radio" id="p1" name="p1option" value="P1 Option1">
<input class="hidden" type="radio" id="p1" name="p1option" value="P1 Option2">
<input class="hidden" type="radio" id="p2" name="p3option" value="P2 Option1">
<input class="hidden" type="radio" id="p2" name="p2option" value="P2 Option2">
<input class="hidden" type="radio" id="p3" name="p1option" value="P2 Option1">
<input class="hidden" type="radio" id="p3" name="p3option" value="P2 Option2">
Related
I have a webpage that contains two set of radio buttons. I want to do; if user select a OS in first fieldset and a language from second fieldset, then user must directed to relevant pages.
Please guide me to complete this page. I am unable to get two radio button values at a time. If I rename the radio buttons like below,
<fieldset id="group1">
<input type="radio" class="radto" name="android"/>
</fieldset>
<fieldset id="group1">
<input type="radio" class="radto" name="english"/>
</fieldset>
It's working, but the problem is users can select more than one OS and language. I need to prevent this. How can I overcome this problem.
<?php
if (isset($_POST['submit'])) {
if (isset($_POST['android']) && isset($_POST['english'])) {
header("location: andro_eng.php");
exit();
}
if (isset($_POST['android']) && isset($_POST['french'])) {
header("location: andro_fre.php");
exit();
}
}
?>
<html>
<head>
</head>
<body>
<form action="" method="post">
<fieldset id="group1">
<li><input type="radio" class="radto" name="a"/> android</li>
<li><input type="radio" class="radto" name="a"/> ios</li>
<li><input type="radio" class="radto" name="a"/> symbian</li>
</fieldset>
<fieldset id="group2">
<li><input type="radio" class="radto" name="b"> english</li>
<li><input type="radio" class="radto" name="b" > french</li>
<li><input type="radio" class="radto" name="b"> spanish</li>
</fieldset>
<input type="submit" value="next" name="submit">
</form>
</body>
</html>
The name attribute has to be the same for the different options:
$( document ).ready(function() {
$('#button').click(function() {
alert($('input[name=os]:checked').val());
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<fieldset id="group1">
<input type="radio" class="radio" name="os" value="android" id="android" />
<label for="a">Android</label>
</fieldset>
<fieldset id="group1">
<input type="radio" class="radio" name="os" value="iOS" id="iOS" />
<label for="b">iOS</label>
</fieldset>
<button id="button" type="button">Get value</button>
And you need to add a value attribute to the radio inputs, otherwise you won't get any value.
Then you can get the values from PHP: $_POST['os'] will return android, iOS or may be empty if no value is selected.
I have several groups of radio buttons that I want to use in an IF statement (or if you have a better solution)
Users will come to the site, select the buttons, then select submit. After submitting, I want the user to see instantly if they should "refer patient" or "don't refer patient".
I am not sure of a couple of things:
How do I make the "submit" button cause the input to be calculated (meaning, the user gets the instant response)
Since there are several combinations of inputs that can create a "refer" or "don't refer" response, can I add multiple conditions to the IF statement? Also, how can I include radio buttons in the statement - do I just use the "value" of the button. I only learned the very basic method of using numbers..
Below is my code so far. I tried to start the IF statement with values. Not sure if doing it right.
Any help is greatly appreciated!
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Indications for Mohs</title>
<?php
$Patient_status='unchecked';
$Primary_status='unchecked';
$Type_status='unchecked';
$BCCT_status='unchecked';
$SCCT_status='unchecked';
$Size_status='unchecked';
$Area_status='unchecked';
if (isset($_POST['Submit'])) {
$selected_radio=$_POST['REFER'];
if (selected_radio == "Healthy" && "Primary" && "BCC" && "Aggressive" && "<0.6" && "H" or "Immunocompromised" && "Primary" && "BCC" && "Aggressive" && "<0.6" && "H")
?>
</head>
<body>
<form name="Indications" action="" method="POST">
<p><h2><strong><u>Indications for Mohs Surgery</u></strong></h2>
</p>
<strong>Patient </strong>
<div alighn="center"><br>
<input type="radio" name="Patient" value="Healthy">Healthy<br>
<input type="radio" name="Patient" value="Immunocompromised">Immunocompromised<br>
<input type="radio" name="Patient" value="Genetic">Genetic Syndrome<br>
<hr>
<strong>Primary vs Recurrent</strong>
<div alighn="center"><br>
<input type="radio" name="Primary" value="Primary">Primary<br>
<input type="radio" name="Primary" value="Recurrent">Recurrent<br>
<hr>
<strong>Type</strong>
<div alighn="center"><br>
<input type="radio" name="Type" value="BCC">BCC<br>
<input type="radio" name="Type" value="SCC">SCC<br>
<input type="radio" name="Type" value="LM">LM or MIS<br>
<hr>
<strong>BCC subtype</strong>
<div alighn="center"><br>
<input type="radio" name="BCCT" value="Aggressive">Aggressive<br>
<input type="radio" name="BCCT" value="Nodular">Nodular<br>
<input type="radio" name="BCCT" value="Superficial">Superficial<br>
<hr>
<strong>SCC subtype</strong>
<div alighn="center"><br>
<input type="radio" name="SCCT" value="Aggressive">Aggressive<br>
<input type="radio" name="SCCT" value="Nonaggressive">Nonaggressive<br>
<input type="radio" name="SCCT" value="Verrucous">Verrucous<br>
<input type="radio" name="SCCT" value="KA">KA - type SCC<br>
<input type="radio" name="SCCT" value="Bowen">In situ SCC/Bowen<br>
<input type="radio" name="SCCT" value="AK">AK<br>
<hr>
<strong>Size (cm)</strong>
<div alighn="center"><br>
<input type="radio" name="Size" value="0.5"><0.6<br>
<input type="radio" name="Size" value="0.6-1">0.6-1<br>
<input type="radio" name="Size" value="1.1-2">1.1-2<br>
<input type="radio" name="Size" value="2">>2<br>
<hr>
<strong>Area</strong>
<div alighn="center"><br>
<input type="radio" name="Area" value="H">H<br>
<input type="radio" name="Area" value="M">M<br>
<input type="radio" name="Area" value="L">L<br>
<hr>
<p>
<input type="submit" name="submit" id="submit" value="Submit">
</p>
<p><strong><u>Definitions</u>:</strong><br>
Nonaggressive SCC: <2mm depth without other defining features, Clark level ≤III<br>
Area H: 'Mask Areas' of face (central face, eyelids, eyebrows, nose, lips [cutaneous/mucosal/vermillion], chin, ear, and periauricular skin/sulci, temple), genitalia (including perineal and perianal), hands, feet, nail units, ankles, nipples/areola<br>
Area M: Cheeks, forehead, scalp, neck, jawline, pretibial surface<br>
Area L: Trunk and extremities (excluding pretibial surface, hands, feet, nail units and ankles)</p>
</div>
</form>
</body>
</html>
If you want to have the submit display a response instantly you should use JavaScript as this does not require a form submission/call to a server. You can use the onsubmit event.
Regarding checking for if a radio button is checked, use the .checked property of an element:
document.getElementById('elem').checked //true or false
Almost everything is wrong with that code.
Let's start...
You don't have a REFER element in your form, so $_POST['REFER'] is never set. To access radio button values, you need to access with their relevant name as the index key to the $_POST[] array. E.g. $_POST['Patient'], $_POST['Primary'] ...etc. Those will give you the value of the radio button selected within that group.
Secondly, your conditional statements are wrong in the if statement. To compare conditional statements, you have to specifically compare the variable with different values every time. You'd have to say
if ($selected_radio == "Healthy" && $selected_radio == "Patient") {
// code goes here
}
And also, to check which radio button was selected, you need to access $_POST['<Radio_group_name>'] and this will give you the value of the radio button selected for that group. e.g.
$_POST['Patient']
would give Healthy if user selected that one for the group.
Is it possible to conditionally add hidden input fields into a form?
eg I have a php form that is adding values to a table and if the appleID = 1 or 2 then I want 1 added to the fruits column of my table and if appleID =3 I want 1 added to the sweets column of my table. I thought I might be able to do something like the below but it is adding all hidden values no matter what I select. Or should I approach this a different way?
<input type="radio" value="1" name="appleID" />
<input type="hidden" value="1" name="fruits" />
<input type="hidden" value="0" name="sweets" />
<input type="radio" value="2" name="appleID" />
<input type="hidden" value="1" name="fruits" />
<input type="hidden" value="0" name="sweets" />
<input type="radio" value="3" name="appleID" />
<input type="hidden" value="0" name="fruits" />
<input type="hidden" value="1" name="sweets" />
Thanks I haven't done much with php so I will need to explore that option further. Thanks for the feedback.
I was also looking at something like the below. But PHP sounds likes the better option.
change field value when select radio buttons
You can either use all values in the radio buttons (1,1,0 - 2,1,0 - 3,0,1) and split them after receiving them in your PHP script or add/delete the hidden fields via JavaScript.
Split Example:
HTML:
<input type="radio" value="1,1,0" name="appleID" />
<input type="radio" value="2,1,0" name="appleID" />
<input type="radio" value="3,0,1" name="appleID" />
PHP:
if (!empty($_POST['appleID']))
{
list($appleID, $fruits, $sweets) = explode(",", $_POST['appleID']);
}
It is better to put that logic into the PHP script instead of using Javascript - because you have to do the validation anyway.
I currently have a form with lets say 5 radio button entries (see below).
What im looking archive is the following:
- Being able to choose multiple radio buttons - lets say 3 and submit the form.
Currently I got it working fine with PHP, SQL, but im only able to choose one radiobutton and submit that.
I figure it would also come in handy being able to deselect a radio button in case you wrongly click one.
My guess is that this can be done through some javascript? Any suggestions? Online examples perhaps?
<form id="pollform" action="poll.php" method="post">
<input id="option-1" type="radio" value="1" name="poll">
<label for="option-1">Select option 1</label>
<input id="option-2" type="radio" value="2" name="poll">
<label for="option-2">Select option 2</label>
<input id="option-3" type="radio" value="3" name="poll">
<label for="option-3">Select option 3</label>
<input id="option-4" type="radio" value="4" name="poll">
<label for="option-4">Select option 4</label>
<input id="option-5" type="radio" value="5" name="poll">
<label for="option-5">Select option 5</label>
</form>
Radio buttons are designed so that only one option from each group (as designated by their shared name) can be selected at once (just like you can only tune a radio to one station).
The input control which allows any number of options to be selected is the checkbox. If you append [] to their names, then the selected options will arrive on the PHP side as an array.
<input type="checkbox" value="1" name="poll[]" />
<input type="checkbox" value="2" name="poll[]" />
As it has same name poll you will not be able to do that as input type radio is specialized in selecting a single value from multiple inputs.
You can use input type checkbox for that and make them as an array:
<form id="pollform" action="poll.php" method="post">
<input id="option-1" type="checkbox" value="1" name="poll[]">
<label for="option-1">Select option 1</label>
<input id="option-2" type="checkbox" value="2" name="poll[]">
<label for="option-2">Select option 2</label>
<input id="option-3" type="checkbox" value="3" name="poll[]">
<label for="option-3">Select option 3</label>
<input id="option-4" type="checkbox" value="4" name="poll[]">
<label for="option-4">Select option 4</label>
<input id="option-5" type="checkbox" value="5" name="poll[]">
<label for="option-5">Select option 5</label>
</form>
LIMIT (with jQuery) the number:
$("input[type=checkbox][name=poll[]]").click(function() {
var numberSel = $("input[type=checkbox][name=poll[]]:checked").length >= 3;
$("input[type=checkbox][name=poll[]]").not(":checked").attr("disabled",numberSel);
});
Radio buttons are designed for only 1 item to be selected, use checkboxes instead.
A very basic question...
How can I only allow the selection of one option in a list of radio buttons?
<form action="process_repair.php" method="POST">
<label for "repair_complete">Repair complete</label>
<input type="radio" name="Yes" value="true">
<input type="radio" name="No" value="false">
</form>
When this code runs, it's possible to select both radio buttons, but I'd like them to interact so you can only select one or the other.
Any help much appreciated! :)
Give them the same name.
<form action="process_repair.php" method="POST">
Repair complete
<input type="radio" name="complete" value="true" id="complete_yes" />
<label for="complete_yes">Yes</label>
<input type="radio" name="complete" value="false" id="complete_no" />
<label for="complete_no">No</label>
</form>
Labels must have a for attribute, directing to the corresponding input's id.
Every input should have same "name"