Yes No check box - checkbox

I'm new at php the form I'm creating has a Yes No checkbox my form works fine except if you check the Yes box and then check the No box they both stay highlighted. How can I make it so if the Yes box is checked and they check the No box the Yes box is unchecked.
If you need my code let me know.
I've tried some of the code for checkbox but being new to php some of it doesn't make any sense.

You probably want to use radio button instead of checkbox.
Radio button will automatically deselect when you choose the other option.
Example :
Gender:
<input type="radio" name="gender"
<?php if (isset($gender) && $gender=="female") echo "checked";?>
value="female">Female
<input type="radio" name="gender"
<?php if (isset($gender) && $gender=="male") echo "checked";?>
value="male">Male
<input type="radio" name="gender"
<?php if (isset($gender) && $gender=="other") echo "checked";?>
value="other">Other
This will render like :
RadioButtonPng

Related

How to reset the value of validation error based on radio button

I have the below code to select Yes\No for selecting the options from Multi Select dropdown. But It is required only when I select the Yes Option from radio. Otherwise the validation message should disappear when I move from Yes to No. (I am disabling the Multi Select in script when the user selects the No optio)
<input id="Option1" name="MyRadio" ng-model="MyRadioData" type="radio" title="Yes" value="Yes" ng-click="Flip('Yes')" />Yes
<input id="Option2" name="MyRadio" ng-model="MyRadioData" type="radio" title="No" value="No" ng-click="Flip('No')" />No
<select id="MultiSelect1" kendo-multi-select name="MultiSelect1" k-value-primitive="true" k-max-selected-items="30" k-placeholder="multiPlaceHolderVendor"
k-ng-model="MyOptions" k-data-source="MyOptionsDS" ng-required="MyRadioData == 'Yes'" validationmessage="Required"></select>
<span data-for="MultiSelect1" data-role="validator"></span>
But the above code is not working though I have used ng-required option for multi select.
Appreciate any help.
If <span data-for="MultiSelect1" data-role="validator"></span> is where messages put, you can handle with ng-show ng-hide like this:
UPDATE
<!-- if you choose no it hide-->
<span ng-hide="MyRadioData == 'No'" data-for="MultiSelect1" data-role="validator"></span>
<!-- if you choose yes it hide-->
<span ng-hide="MyRadioData == 'Yes'" data-for="MultiSelect1" data-role="validator"></span>
Here is a plnkr with a button but it does the same, i will help you how this work.

How to identify the radio button in selenium, if id and name have the same value

I have tried to make Selenium click a radio button. Selenium is unable to select any of the radio buttons because id and name for the radio buttons are the same.
I am adding the html code below:
<label for="gender">Gender</label>
<input id="gender " name="gender" value="M" type="radio"/>
Male
<input id="gender " name="gender" value="F" type="radio"/>
Female
<label class="error" for="gender"/>
Try this below code.
If you want to click on Male then use below code using xpath locator..
WebElement radio_male = driver.findElement(By.xpath("//input[#value='M']"));
radio_male.click();
OR
If you want to click Female radio button then use below code using xpath locator.
WebElement radio_female = driver.findElement(By.xpath("//input[#value='F']"));
radio_female.click();
Explanation of xpath:- Use value attribute of <input> tag.
Boolean btnSelected = odriver.findElement(By.id("enrollUserOptionsDiv")).isSelected();
if(btnSelected = true){
if(odriver.findElement(By.xpath("//input[#value=\"No\"]")).isSelected())
{
System.out.println( odriver.findElement(By.xpath("//input[#value=\"No\"]")).isSelected());
odriver.findElement(By.xpath("//input[#value=\"Yes\"]")).click();} //fails at this line

AngularJS: ng-model-options bind form value on Submit doesn't work with multiple selections

I have a form with three radio buttons, and deferred binding to model on click of submit. Live example here
This works perfectly fine in the happy path scenario:
Select radio1 > click submit gives radio1 as the result.
But in the following scenario it breaks:
Select radio1 > click submit > gives radio1
Now select radio2 > then radio3 > and then click submit.
This gives radio2 instead of radio3 as the bound value.
Basically, if I make multiple changes to the radio group, only the first change gets captured. How can I change this behaviour to reflect the last change instead?
You have to use allowInvalid : true in ngModelOptions to validate correctly instead of the default behavior of setting the model to undefined. See documentation.
<input type="radio" name="radio" value="radio1" ng-model="radioValue" ng-model-options="{updateOn: 'submit', allowInvalid : true}" >
<input type="radio" name="radio" value="radio2" ng-model="radioValue" ng-model-options="{updateOn: 'submit', allowInvalid : true}">
<input type="radio" name="radio" value="radio3" ng-model="radioValue" ng-model-options="{updateOn: 'submit', allowInvalid : true}">
Working Plunker Link

Disable a textbox on page load in AngularJS

I have a text box and two radio button controls with yes or no value. If I click on Yes, the text box should be enable and it should be disabled on No selection. I have used ng-disabled property.
But, if user selects No, saves the file and reopens it, the text box is getting enabled again. Is there a way to save the text box state?
I have tried using disabled="" on textbox. but if user selects yes, enters some value and saves the files, the textbox is getting disabled again. if user selects Yes, the textbox should not be disabled till he selects No
I am talking about index.html file.
Below is my chunk of code:
<input type="radio" name="something" value="1" ng-model="checkboxSelection"/>Checkbox 1
<input type="radio" name="something" value="2" ng-model="checkboxSelection"/> Checkbox 2
<input type="text" ng-model="somevalue" name="somevalue" ng-disabled="checkboxSelection=='2'"/>
try this
<input type="checkbox" ng-click="disable = !disable">
<input type="text" ng-disabled='disable'/>
If you want to clear the value of the input after check no, use a function in you're controller
<input type="radio" ng-model="disable_input" ng-value="true" />
<input type="radio" ng-model="disable_input" ng-value="false" />
<input type="text" ng-disabled="disable_input" />
I'm not sure if you want to use and input or textarea as your "textbox" but all you would need to do to make it a textarea instead is use the ng-disabled in the last input element in a textarea instead.

force a a radio box to be be checked value in jquery mobile

How do a force a a radio box to be be checked value in jquery mobile?
I think it has to do with class=ui-btn-active.
<input type='radio' name='myradio' id='radio-choice-1' value='1' /><label for='radio-choice-1'>Station 1</label>
<input type='radio' name='myradio' id='radio-choice-2' checked value='2' /><label for='radio-choice-2'>Station 2</label>
<input type='radio' name='myradio' id='radio-choice-3' value='3' /><label for='radio-choice-3'>Station 3</label>
I'm not sure what you mean by 'force' - are you asking how to programatically change the state of a radio button? With jQuery Mobile, you must refresh the radio button after updating it's attribute in order for it's UI to be updated. From the docs:
$("input[type='radio']").attr("checked",true).checkboxradio("refresh");
Also note that with HTML4, boolean attributes such as disabled and checked take their names as values when enabled. So simply putting in checked is not valid but must be checked='checked' instead.

Resources