Setting a radio value to yes upon checking another field [duplicate] - javascript

This question already has answers here:
Check a radio button with javascript
(7 answers)
Closed 5 years ago.
Quick question I'm unable to resolve... I have a radio button with values of yes or no.
Basically I'm doing this:
if (complete === '1') {
getElementById('test-radio').value('Yes')
}
But it's not setting this to yes, it's still defaulting as no...
Any advice on how I can make this work?

You can use either radioButton.checked=true;
What you are doing isn't javascript syntax.
if (complete === '1') {
getElementById('test-radio').checked=true;
}

Related

The right way to check if an html element exist [duplicate]

This question already has answers here:
How can I check if an element exists in the visible DOM?
(27 answers)
Closed 4 years ago.
What is the proper way to check if an html element exist in a webpage.
I do like this:
if (document.getElementById('container') !== null) {doThis()}
How good is this?
What are other ways?
Answered
I was looking for
document.body.contains(element))

Find and delete cookie with javascript [duplicate]

This question already has answers here:
How to delete a cookie?
(13 answers)
Closed 6 years ago.
How would like to with javascript find a cookie that starts with 'AzureAppProxyAccess' and delete that cookie? It always has a series of random numbers at the end of the name. It is in the same domain so I have access to it.
This is what I have tried with jquery but I would like just javascript.
for (cookie in $.cookie()) {
if(cookie.substring(0, 19) === "AzureAppProxyAccess") {
$.removeCookie(cookie);
}
};
You can use indexOf in strings.
cookie.indexOf('AzureAppProxyAccess') > 1 ? doSomething : somethingElse
Or, like it was said in one of the comments, use RegEx.

how to view the answer of a js function in a html input? [duplicate]

This question already has answers here:
Set the value of an input field
(17 answers)
Closed 7 years ago.
I've always been wondering this, but all websites seem to be answering the opposite (how to make text typed in an input be the input of a function).
Is there a way to do it?
Is this what you want to do?
function myFunction() {
// some functionality here
// this function must return something
}
var input = document.querySelector('input');
input.value = myFunction();
This will set the value of the input element to the value returned by myFunction.

Comparing variable to empty jquery object in if condition [duplicate]

This question already has answers here:
How do you check if a selector matches something in jQuery? [duplicate]
(11 answers)
Closed 9 years ago.
In the jQuery accordion API, it says "If the accordion is collapsing, ui.newHeader and ui.newPanel will be empty jQuery objects."
How can I check if ui.newheader is an empty jQuery object? I've tried it like this:
if ($(ui.newHeader) == null)
{
...
}
,like this:
if (ui.newHeader == null)
{
...
}
and this:
if ($(ui.newHeader) == "")
{
...
}
So basically, this is a question about jquery/javascript syntax :) Thanks
What you want is to know if there is 0 element in the set. Do it like this :
if ($(ui.newHeader).length==0) {
if (!$(ui.newHeader).length)
or
if (!$(ui.newHeader)[0])
jQuery object is array like collection. So, it is empty means, it's length property is 0.
if(!$(ui.newHeader).length) {...}

Is there a JavaScript alternative to isNaN()? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
JavaScript logic for isNaN()
Hey all I want is to check that the entered value in a textbox is not a number or without using the function isNaN();. Is there any way?
parseFloat(value)!== +value;
But what is wrong with isNaN(value)?

Categories

Resources