Make a word a radio button? - html

I want to have two options: yes and no. I want the user to have to select one so obviously I'd go with a radio button but is there a way I can set it so that the user can just click on yes or no instead of a radio button in order to select their choice?
Thanks in advance for any help

I'd go on #sal niro option, but if you have other plans for the radio(I'm not sure because you'r question require more explnation)
here is an example for using jQuery to trigger a radio input type by a simple div click.
$(function() {
$("#yes").click(function(e) {
$("#rYes").click();
});
$("#no").click(function(e) {
$("#rNo").click();
});
});
#yes, #no {
display: inline;
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="yes">Yes</div> | <div id="no">No</div> <br />
Yes result:<input type="radio" name="test" id="rYes" /> <br />
No Result: <input type="radio" name="test" id="rNo" />
jsFiddle Example

You could go for a solution like this too, it requires some Javascript: fiddle
<button value="yes">Yes</button>
<button value="no">No</button>
JS
var buttons = document.getElementsByTagName('button');
for (i = 0; i < buttons.length; i++) {
buttons[i].addEventListener('click', function () {
alert(this.value);
}, false)
}

Yes, if you use a <label> then this will associate the label text with the input field.
You can either use the for attribute or wrap the label around the input field.
See this related question - Should I put input tags inside a label tag?

I do quite believe you're asking how to produce a radio button with yes and no.
If so,do this:
<form action="">
<input type="radio" name="buttona" value="yes">Yes<br>
<input type="radio" name="buttonb" value="no">No
</form>
Here is what each sentence does:
input type="radio"
Basically states that the type of form you want the user to interact with are the 2 radio buttons
**name="buttona"**Basically states what group of radio buttons this belongs to,so that if only one button is clicked,the rest are unselected.
Yes This is what you what appears next to the buttons.
Hope this helped.

Related

how to get "NA" value if radio button is not selected or disabled?

I am trying to get value as "NA" if there is no radio button option is selected.
Right now i use this code $("input[name='question']:checked").siblings('label').text()
but by this code i am getting value as Blank if any radio button is not checked or question is disabled.
Please check the below sample code this might be helpful:
I have used the querySelector DOM method which uses common name porperty of radio buttons inside it.
<label>
<input type="radio" name="question" value="1"> Question1
</label>
<label>
<input type="radio" name="question" value="2"> Question2
</label>
<script>
$(document).ready(function(){
var getSelectedValue = document.querySelector( 'input[question="type"]:checked');
alert("getSelectedValue>>>"+getSelectedValue);
if(getSelectedValue!= null)
{
console.log("radio button selected")
}
else{
console.log("not selected")
//here you can add your logic for 'NA'
}
});
</script>
I have used this $("input[name='question']:checked").siblings('label').text() || "NA" and it works.Let me know if iit is not a good practice.

Buttons in html/react/bootstrap that do not require the click to be released

I've got a very large grid of buttons that a user will use to set their availability. Currently, the user must click each button one at a time, which works, but can get really repetitive.
I was hoping to create a grid of button-like objects where the user can select multiple buttons by holding down their mouse button and dragging.
Is there any sort of equivalent to a button in HTML, React or Bootstrap where the click does not need to be released?
If not, would anyone here have any sort of suggestion?
Thank you
<script language="JavaScript">
function toggle(source) {
checkboxes = document.getElementsByName('foo');
for(var i=0, n=checkboxes.length;i<n;i++) {
checkboxes[i].checked = source.checked;
}
}
</script>
<input type="checkbox" onClick="toggle(this)" /> Toggle All<br/>
<input type="checkbox" name="foo" value="bar1"> Monday<br/>
<input type="checkbox" name="foo" value="bar2"> Tuesday<br/>
<input type="checkbox" name="foo" value="bar3"> Everyday<br/>
<input type="checkbox" name="foo" value="bar4"> Days that don't end in 'Y'<br/>
Source

Swap button and text in input type="file"

I want to swap text and button in input type="file". Is it possible to use only html and css for this task or only js solutions are suitable?
Keywords are ::-webkit-file-upload-button and ::file-selector-button. The solution will depend on browser version.
See also
-webkit-file-upload-button css implementation for firefox
or
https://css-tricks.com/snippets/css/force-file-upload-input-button-to-right-side-in-webkit/
The input can be hidden and embedded between a label and a button. Javascript then carries over the functionality:
<label for="upload-file" style="width:130px; display: inline-block; border: 1px solid #ccc">Choose file</label>
<input id="upload-file" type="file" style="display:none" onchange="this.previousElementSibling.textContent = this.previousElementSibling.title = this.files[0].name">
<button onclick="this.previousElementSibling.click()">Browse...</button>
http://jsfiddle.net/nxmwhsap/
If you want to swap the text of a button when the button is clicked, you have to call a JS method, nothing fancy but just to retrieve the text from the input field since the user entered text can dynamically change.
HTML
<input type="button" class="swapBtn" id="swapBtn" onclick="swapText()" value="button text">
<input type="text" id="inputTxt" class="inputTxt">
JS
function swapText()
{
var textStr = document.getElementById("inputTxt").value;
var btnEl = document.getElementById("swapBtn");
btnEl.innerHTML = textStr;
}

HTML Label "For" Value

I have a label tag that I am trying to link to an input type checkbox tag. I have multiple labels and multiple checkbox inputs, and they all have the same id and the same name, but different values. Can someone instruct me as how to construct a label that links to a value rather than an id? So this:
<label for="8994"></label>
Would link to:
<input id="member_ids_" name="member_ids[]" type="checkbox" value="8994">
Or is this not possible?
The label's for attribute must match the ID of the <input> element it refers to. In your case it would be something like:
<label for="member_id_8994"></label>
<input id="member_id_8994" name="member_ids[]" type="checkbox" value="8994">
The 'for' for the form element must match with the ID of the same form element.
<label for="id_1"></label>
<input id="id_1" name="member_ids[1]" type="checkbox" value="8994">
<label for="id_2"></label>
<input id="id_2" name="member_ids[2]" type="checkbox" value="8994">
<label for="id_3"></label>
<input id="id_3" name="member_ids[3]" type="checkbox" value="8994">
<label for="id_3"></label>
<input id="id_3" name="member_ids[4]" type="checkbox" value="8994">
Your DOM elements must have different IDs.
Even if each ID is just set to whatever that value is... ...or whatever.
They can not have the same ID.
Once you've got that out of the way, setting for on a label becomes really simple.
I doubt if that is possible. Label's for are tied to the id attribute of inputs. One way to do achieve your objective maybe through javascript, knockout's declarative bindings for instance.
check it our here: http://knockoutjs.com/documentation/introduction.html
Something along this line:
<label data-bind="click: myInput"></label>
<input type="checkbox" id="hello">
<script type="text/javascript">
var myInput= {
//implement the function to bind the label to the input#hello here
}
};
</script>
http://knockoutjs.com/documentation/click-binding.html
A jQuery solution that probably doesn't work.
$(function() {
ModifyLabels({target: $('input')});
$('input').change(ModifyLabels);
});
function ModifyLabels(eventObject) {
var inputs = $(eventObject.target);
input.each(function(i, input) {
$('label').each(function(i, label) {
if ($(label).attr('for') == $(input).val()) {
$(input).attr('id', $(input).val());
}
});
});
}

Clear or Reset Button

I have a form and a working reset button. When i click the button all inputs and text area boxes are clear. I was wondering if there's a way to create a clear/reset button that will clear only some inputs and not what i have inside my text area box.
Here's the jsfiddle solution.
<form>
<input type="text" class="clearit" /><br />
<input type="text" class="clearit" /><br />
<input type="text" class="clearit" /><br />
<textarea id="t5"></textarea><br />
<input type="reset" id="reset" />
</form>
$(document).ready(function(){
$('#reset').on('click',function(e){
e.preventDefault();
$('.clearit').val("");
});
});
Assign all input elements a class let suppose inputs and different ids let suppose the id of text area is text_area.
<input type = "textarea " id = "textarea ">
Now with jquery
$(function(){
$('.inputs').each(function()
{
var id = $(this).attr('id');
if(id == 'textarea '){
}else{
$(this).attr('value',"");
}
});
})
Done!
use jquery it will help u , give the class to fields which u want to clear on click of button and give id to your button
$('#id_of_button').click(function(){
$('.input_field_class').val("");
});
See the link
http://www.javascript-coder.com/javascript-form/javascript-reset-form.phtml
Basically rather than calling a form.reset() from the reset button, call an external function which clears out the fields you require and leave the remaining as it is.
Hope it solves your problem!