Syntax for setting checkbox value(as checked) in dojo dynamically - javascript

How to set the value of a check-box to checked dynamically using dojo? In dojo toolkit site I saw it was written to use key value pair for setting the checkboxWidget but am unsure about the approach. Can someone please suggest?
Here is my approach but it doesnt work .How can I fix this?:
checkboxWidget.set("","checked");

If you use set to assign a value to a property, the first parameter is the property name followed by the value.
checkboxWidget.set("checked", checkedValue);

Related

AngularJS - Bind input to value with filter and update it

I have an input bound to an object property and with a filter applied to it.
<input value="{{object.field | filter}}">
The problem is that if I programmatically change object.field, the value displayed inside the input doesn't change, however in the DOM Inspector I see the correct (new) value. I verified to digest/apply the changes to the scope and the object.field variable does change correctly, the issue seems to be only in the input displayed value.
I cannot provide an example since there's too much code involved.
Does anyone know where I should look for errors??
No need to set value in that way. ng-model takes care of it.
Valid syntax is:
<input ng-model="object.field">
For filtering you can look at this answer:
Using angularjs filter in input element
I think you should use ng-model to bind your data into input box instead {{expression}}

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()

How to Get ClientSide Value from ASP.net Custom Control?

How can I get ClientSide(JavaScript) Value for My ASP.net Custom Control?
for example I want to get a value like this:
var selectedItemID = getElementById("<%=MyControl1.ClientId%>").value;
How can i set a specific Value in my control scripts to get it from ".value" property like above?
Additional Note:
i want ".value" property(javascript) to get the dropDown control(one of my controls in my custom control) selected Value.
You can have a custom attribute for your custom control while it is rendering and bind the necessary value. Then in the Clientside, you can get the custom attribute and get the corresponding value from it.
For ex: Say suppose you are adding a custom attribute to your control using the code below while rendering,
MyControl.Attribures.Add("attributeName","Value");
then you can get the value in the clientside using the code snippet below.
var controlValue = $("#"+"<%= MyControl1.ClientID %>").attr("attributeName");
This would give you the value that you stored in the custom attribute of the control.
I'm not sured but You can try this:
var control = $find("<%= MyControl1.ClientID %>");
may be following link usefull for you No error message displayed for custom validator
just do like this way using jquery:
$("<%= MyControl1.ClientID %>").val();
using javascript:
var Val=document.getelementbyid("<%= MyControl1.ClientID %>").value;
hope this help.
If your control rendered as an input, your code will work but if it is anything else, such as a span or label, you need to use .innerHTML instead of .value

Access to Label value with Javascript

I need to access to a value in a checkbox, the atribute value has content, so i need to place the id somewhere else i created a label, but i have not access to that value
alert(check[i].label); // doesnt work
where else can i place a value in checkbox.
Please dont write that i can do this
<input type='checkbox' id='bla' name='mybla' vlaue='myvalue'> Hy
Where can i place some other values ?
I tryed with this
<input type='checkbox' id='bla' name='mybla' vlaue='myvalue' label='myothervalue'> Hy
first i get all checkbox ect... and in the for loop i did this
alert(check[i].label); // doesnt work
How can i do that?
It is indeed possible to store the extra data as a custom attribute on the <input> element. When you want to read the value, you can do it like this:
alert(check[i].getAttribute('label'));
Since you have tagged the question jQuery, here's the trendy version:
alert($(check[1]).attr('label'));
See these discussions if you are woried about using custom HTML attributes.
When I am being tempted to do this, I prefer to use a related hidden element to store the "other value". It feels cleaner to me, and I also don't have to wade through the validation warnings that otherwise could come at me.
Is that something you can use here?

Categories