dynamically set checked checkbox in gridview in javascript - javascript

I am having id or values in hidden field. I wanted to set checked=true to checkbox which is in gridview ItemTemplate using javascript only(no jQuery please)

document.getElementById("ID").checked = true/false

all your id's should be unique. however, you can implement it yourself, by traversing all "checkboxes" in page, and checking their "id" attribute. see getElementsByClass which uses same principal.

Related

How to give a HTML element in NetSuite an ID in DOM?

I try to use jQuery to give the element value in NetSuite to test, but cannot find out the HTML DOM ID of some customized drop-down list. Not the internal ID.
E.g.
<input type="text" id="soid">
However some ID for the customized elements can be found, and some are not.
Can we add an HTML ID for the element in NetSuite?
are you trying to get the ID of this input field using JQuery?
If so just use $('#soid').val(); Or to get the text in the field $('#soid').text();
Select a value on the dropdown
Right click the dropdown and press INSPECT
look for a hidden input with the similar ID to your dropdown with the class named nldropdown
set THIS field manually using Jquery
We do this alot and there is not straightforward docs on it

Check for checked checkbox validatejs

I'm using validatejs for my forms validations. How can I check if my checkbox is checked or not? Or any other attribute?
https://validatejs.org/
if you just want the value whether checkbox is checked or not you can do it in plain JavaScript as document.querySelector("input[type='checkbox']").checked or simply using id document.querySelector("#id_of_chkbx").checked

How to store input type checkbox into json object using either Javascript or jQuery?

I wanted to store all my clicked input accordions(<input type="checkbox">) into json object, I have tried it but it is storing/taking the last input accordion clicked event only, it is not storing/taking all the input clicked accordions that is whatever I click on any accordion(of <input type="checkbox">) that should store into json object using either Javascript or jQuery ?
I am not sure where I am doing wrong ? Please help me regarding this ? Thanks in advance. Sample fiddle.
Because you are doing submitButtonValue[name] = $(this).val(); and the name you are getting it from $(this).attr('name'); on click of checkbox which is same for all the checkboxes. So everytime it replaces the value since object will have only one name contained. I would suggest you to either use different names for each checkbox or find some other way to uniquely store your checkbox values.
A Demo here

Checkbox creation using clone() method of jquery

I my form I have duplicate checkbox like
<input type="checkbox" name="todayDimensionStones[].isIssued" id="isIssued" value="Yes"/>
I am creating another checkbox using above using clone() method using jquery.The checkbox box is created successfully.But when I checked and submit the form containing the newly created checkbox and retrieve the value of newly created checkbox,it seems to be empty ie ''. What I to do solve this problem.If any have an idea ,please share with me
You have to change the attribute name
or you have to add [] at the end of the name.
If you send two inputs with the same name without [] at he end, php gives you the last one only.
If anyone stumbles about this: value attribute is probably missing. Set it manually after cloning:
On the cloned element with some checkboxes do:
$clone.find(':checkbox').each(function() {
$(this).attr('checked','checked')
});
Thats on IE9. See https://bugs.jquery.com/ticket/10550

get radio box value in jquery

Am I under the wrong impression that jquery or JS can retrieve the values of radio buttons in a form? The reason i ask is because in my code the script i use to check for all fields in a form, does not seem to recognise the value in id="contact2" in the form, which is a radio group. I have posted my code at jsfiddle.net and would appreciate some feedback as to how I can correct this. Many thanks
Fiddle: http://jsfiddle.net/xGrb9/
You need to do it like this:
$('input:radio[name=bar]:checked').val();
Because of how radio buttons are checked/unchecked and their values are stored. (from the jQuery docs). You also need to make sure that the radio buttons have different IDs, which is a classic gotcha.
Finally, when testing if a radio button has not been selected at all, make sure to test against undefined and not an empty string for compatibility across browsers.
EDIT: looked at your code, and you need to do two things:
1. Change IDs of the buttons, to something like "contact2a" and "contact2b" so they are unique.
2. Change your var customer2 = line to var contact2=$("input[name=contact2]:checked").val();
Change this line:
var contact2=$("#contact2").val();
to:
var contact2=$('input[name="contact2"]:checked').val();
You need the checked because otherwise it finds both inputs.
Also, technically, all IDs should be unique, ie, not used on 2 elements on the page.
You should be able to use .val()
See this: http://api.jquery.com/val/
Both of your radio buttons have the same ID. That doesn't work in HTML. You'll have to refer to the buttons separately and select the one that is checked.
You can simply call
$("[name=contact2]:checked").val()

Categories