I am making a form and the radio button html is
<p>Response Required?
<label><input type="radio" name="required" vaule="yes" checked="checked">Yes</label>
<label><input type="radio" name="required" value="no" >No</label>
</p>
however when looking at the $_POST data after the form is submitted I get [required] => on instead of a "yes" or "no" any thoughts?
Try first to fix "vaule" to "value".
<p>Response Required?
<label><input type="radio" name="required" value="yes" checked="checked">Yes</label>
<label><input type="radio" name="required" value="no" >No</label>
</p>
value spelling is wrong at 1st radio button
Related
I have a drop down that's numbered 1-30. So if I select '2', my radio buttons will appear like this:
<input type="radio" id="yes-sdf-1" name="field[1][sdfradio]" value="Yes" />
<input type="radio" id="no-sdf-1" name="field[1][sdfradio]" value="No" />
<input type="radio" id="yes-sdf-2" name="field[2][sdfradio]" value="Yes" />
<input type="radio" id="no-sdf-2" name="field[2][sdfradio]" value="No" />
How do I get the individual values of the radio buttons because I want to set conditions that will only affect those with the same name.
Here is an example to give you an idea.
Try this:
$('input:radio').click(function(){
alert($(this).attr('name'));
});
This will return the name of the radio button.
JSFiddle
In the image below, if I click either male or female text, I want the checkbox to be checked. How can I do that?
Second option is to wrap both checkbox and text in a label. It will work too:
<label>
<input id="male_checkbox" name="gender" type="checkbox" value="male" /> Male
</label>
You need to use label with for attribute:
<label for="male_checkbox">Male</label>
<input id="male_checkbox" name="gender" type="checkbox" value="male" />
<input type="checkbox" name="male" id="male" value="male"><label for="male">Male</label>
This will allow the user to click either the name or the checkbox
Do the same for female.
Unfortunately I haven't been able to find exactly what I'm looking for online to resolve this.
At any rate, I have three radio buttons and I need to push the selection of a single button selected from the list into MySQL.
Currently using the below as my radio buttons & submit:
<input class="radiobutton" type="radio" name="1" id="1">1</div>
<input class="radiobutton" type="radio" name="2" id="2">2</div>
<input class="radiobutton" type="radio" name="3" id="3">3</div>
<input type="submit" name="submit" value="Update">`
Can someone help me with the syntax to grab the selected radio button and insert it into MySQL?
An example of the syntax would be
UPDATE tblwhatever.setting SET value='$x' where setting='Y';
Consider the following:
<input class="radiobutton" type="radio" name="radio" id="1" value="1" onclick="document.getElementById('2').checked = false;"/>
<input class="radiobutton" type="radio" name="radio" id="2" value="2" onclick="document.getElementById('1').checked = false;"/>
Note that i gave them the same name attribute. When the form is submitted we will retrieve $_POST['radio'] and the value will determine which radio button was selected. The onclick attribute will uncheck the other radio button if selected.. eg: if radio id="1" is being checked uncheck id="2"
<form method='POST' >
<input class="radiobutton" type="radio"
name="radio" id="1" value='1' checked>
<input class="radiobutton" type="radio"
name="radio" id="2" value='2'>
<input class="radiobutton" type="radio"
name="radio" id="3" value='3'>
<input type="submit" name="submit"
value="Update">`
</form>
in php code should be like this :
<?
$radio = $_POST['radio'];
$query = mysql_query('update "your table" set column1=$radio WHERE some_column=some_value);
?>
I try to implement the follwing code:
<?php
$yesno1="";
$yesno2="";
$option1="";
$option2="";
$option3="";
if(isset($_POST['submit'])){
$yesno1=$_POST['yesno1'];
$yesno2=$_POST['yesno2'];
$option1=$_POST['option1'];
$option2=$_POST['option2'];
$option3=$_POST['option3'];
}
?>
<form method="POST" name="contact_form"
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<input type="radio" name="yesno1" value="yes" style="outline:0;"/>Yes
<input type="radio" name="yesno1" value="no" style="outline:0;"/>No
<input type="radio" name="yesno2" value="yes" style="outline:0;"/>Yes
<input type="radio" name="yesno2" value="no" style="outline:0;"/>No
<input type="checkbox" name="option1" value="Milk"> Milk<br>
<input type="checkbox" name="option2" value="Butter" checked> Butter<br>
<input type="checkbox" name="option3" value="Cheese"> Cheese<br>
<input type="submit" value="Submit" name='submit'>
</form>
Once I click submit button, normally the value I seleted in radio and marked in the checkbox are gone, so how can I keep the value even after the click the submit button or refrsh the page using php, javascript is fine as well, would be better if any one can help me with it on both php and javascript since I am not very good on both of them, thanks for kind help:)
An example below
<input type="checkbox" name="option1" value="Milk" <?php echo ($_POST['option1'] == 'Milk' ? 'checked' : '') ?>> Milk<br>
From MDN:
The input (<input>) element is used to create interactive controls for
web-based forms.
Attributes
type
[...]
radio: A radio button. You must use the value attribute to define the
value submitted by this item. Use the checked attribute to indicate
whether this item is selected by default. Radio buttons that have the
same value for the name attribute are in the same "radio button
group"; only one radio button in a group can be selected at one time.
This is a basic HTML question. Learn to walk before you run ;-)
I have 2 following radio boxes in a form,
<input type="radio" name="radio" value="yes" class="radio" /> Yes
<input type="radio" name="radio" value="no" class="radio" /> No
How can i recieve the value of the radio button once the form is posted (in PHP)
Once it is posted on the same page, how can I remember the selected radio button and keep that checked?
Thanks.
1) The value of the radio button is saved in $_POST only if any of the choices was selected.
if (isset($_POST['radio'])) // if ANY of the options was checked
echo $_POST['radio']; // echo the choice
else
echo "nothing was selected.";
2) Just check for the value and add checked='checked' if it matches.
<input type="radio" name="radio" value="yes" class="radio" <?php if (isset($_POST['radio']) && $_POST['radio'] == 'yes'): ?>checked='checked'<?php endif; ?> /> Yes
<input type="radio" name="radio" value="no" class="radio" <?php if (isset($_POST['radio']) && $_POST['radio'] == 'no'): ?>checked='checked'<?php endif; ?> /> No
<input type="radio" name="radio" value="yes" class="radio" /> Yes
<input type="radio" name="radio" value="no" class="radio" /> No
u get radio value using $_POST['radio'];
simple bro,
<input type="radio" name="radio" <?php if($_POST['radio']=="yes") echo "checked";?> value="yes" class="radio" /> Yes
u have to identify radio box by value man
How can i recieve the value of the radio button once the form is posted (in PHP)
$_POST['radio']
Once it is posted on the same page, how can I remember the selected radio button and keep that checked?
Add a checked attribute if the value is equal to $_POST['radio'].
1) u will receive only that radio box value via POST which is checked
$radio_value=$_POST['radio'];
2)
<input type="radio" name="radio" value="yes" class="radio"
<?php echo ($radio_value == 'yes') ? 'checked="checked"' : ''; ?>/> Yes
<input type="radio" name="radio" value="no" class="radio"
<?php echo ($radio_value == 'no') ? 'checked="checked"' : ''; ?>/> No