checkbox in YUI DataTable - javascript

I'm using a column of checkboxes in a YUI DataTable, I works fine. But I haven't found a way to put a name and value attribute so I can use when the form is submitted.
Thanks in advance.

Does the API reference at http://developer.yahoo.com/yui/docs/YAHOO.widget.CheckboxCellEditor.html help?

In order to get a name and value attribute, you use a checkbox like this:
<input type="checkbox" name="the_name" value="the_value" />
In your server-side code, you would look into the POST or GET data for the name of the checkbox. If it is there, the checkbox was checked. If it isn't there, the checkbox was not checked.
http://www.w3schools.com/HTMLDOM/dom_obj_checkbox.asp

How I reed a attribute for a checkbox, if I use YUI of Yahoo. Normaly I can use "document.getElementById(objeto).checked" but with YUI not work?.

Related

Want to take a radio and checkbox value from one form to another

I have values from one form that need to be transferred to another.
var manager = $('input[type=checkbox]:checked').val();
I'm capturing the value with this. and trying to send it to this.
$('input[type=checkbox]:checked').val(manager);
but I don't know what to put into the next set of jquery to transfer it over.
.val() works for strings/numbers but not checkboxes or radio buttons which I am trying to do.
Please advice.
Try jQuery prop() function to transfer the state of one checkbox to another.
Also use correct selectors. $('input[type=checkbox]:checked') will only select CHECKED checkboxes.
see this fiddle for an example: https://jsfiddle.net/iPirat/p5f07br4/
in this fiddle, the checkbox in the first form is selected similarly to what you did.
the checkbox insecond form is selected using an ID.

Angular: $setPristine on Form and Checkbox Issue

I've got a form that doesn't allow you to check checkboxes on the first entry, which is very weird. It's almost like it doesn't register the click.
If however, you submit the form and try and check the same checkboxes after submitting the first form, it allows you to check the checkboxes. Why is this?
This is what my checkboxes look like:
<label ng-repeat="sector in sectors" for="{{sector}}">
<input type="checkbox" id="{{sector}}" value="{{sector}}" ng-model="newService.sectors[sector]">{{sector}}
</label>
I'm also trying to work out how to implement $setPristine on this form so it gives the form a class of .ng-pristine when submitted.
I'm very new to Angular and am slowly trying to understand how this all works.
I've set up a Fiddle here: http://jsfiddle.net/nh63w6e0/2/
Any help is appreciated. Thanks in advance!
The Problem
Using your JSFiddle example, if you look at the console while clicking in the checkbox, you'll see the error:
Cannot set property 'health' of undefined
That's because $scope.newService wasn't created, and you were trying to do something equivalent to $scope.newService['health'] = true while checking the checkbox. So, as you can see, $scope.newService was undefined.
The Solution
You should add a call to resetCreateForm to initialize your $scope.newService property.
JSFiddle (check out the last line, with the comment)
Edit:
Addressing your need to use the $setPristine, you could check this JSFiddle out.
All you have to do is add the name attribute on the form and call it as a $scope property by its name. Then you call the $setPristine() on the form property.

How can I clear input text in bootstrap -UPDATED

I have a simple modal in bootstrap 3.0.2 and it has a 2 simple input type="text" I would like to clear it. I have seen example but they are for bootstrap 2 and don't work with my modal. Does any one know how to clear or reset this input text inside a modal when I click on the "reset" button.
-Thank you in advance.
Update: after using #davethecoder solution works like a charm, I still need help clearing 1 of the input text its under the date class:
<input id="#item" type="text" class="date-picker form-control" />
Any chance anyone knows how to clear this one?
-Thank you for helping me.
twitter bootstrap is a CSS framework for modelling response web layouts. If you are using jquery, the code to clear an element is $("#itemid").val('');
easiest would be to give each item a class, and set this value based on class, or as an alternative, you can loop through items of specific formid and reset to clear that way. Personally I would just do this class based, as this will essentially have the loop code per item, within the jquery framework.
I mentioned jquery here, because you had a jquery tag
Oh,just I found that the attribute id of your input element contains '#',it may lead to some unknown mistake. It is best to remove the '#' on your <input>.
If you are using jQuery, just use a function call like this to clear input:
$('#item').val('');
If you're not using jQuery, just use Javascript function like this:
document.getelementById('item').value = "";

Jquery - SerializeArray() checkbox that is not "checked"

so I am trying to implement the Jquery .serializeArray() method to transform a form into a JSON string to send it out in a request. This works great for my form except for checkboxes and radio buttons. The only time this works properly is when they are checked. Sometimes, I need to know if they are unchecked. They still need to get serialized.
I suppose I could manually loop through the form and grab the values and build the JSON object, but that would not be optimal.
According to the Jquery documentation found here: Jquery Docs anything that fits the W3 standards for a successful control found here should get included. Unfortunately, this does not include checkboxes that are not checked. Does anyone have a work around for this behavior? Thanks in advance...
var form = document.getElementById('f');
console.log($(form).serializeArray();
That spits out the serialized form with the checkboxes that are not checked excluded...
If you really want to use checkboxes and radio buttons, have those input fields update a corresponding hidden field. That way, the hidden input will always be sent.
how about trying this, I had a similar problem, I thought unchecked checkboxes should have a value as well, here is a quick work around,
add an extra class on each checkbox on your form "cbx"
make data an array from the form with serialise
then loop through all checkboxes with a class of "cbx"
and add them to the array with a value of 0, AFTER the array has been created with (serializeArray())
when you post the data you will see the unchecked checboxes and values of 0 will get transferred with the post.
var data = $('#form').serializeArray();
$(".cbx:not(:checked)").each(function() {
data.push({name: this.name, value: '0' });
});
$.post("testpage.asp", data);
An alternative would be to use a jQuery plugin. For example, serializeJSON has the option to set the value for unchecked checkboxes like this:
$('form').serializeJSON({checkboxUncheckedValue: "false"});
In any case, it is usually best to use hidden inputs for unchecked values.
Alright, so I developed a workaround.
Basically I wrote a function to compare the original JSON object to the serialized form. As I looped through, I compared the components. If there was a discrepancy, I pulled the component off the form and manually inserted it into the JSON. I used the array.splice() method to add the missing components. Worked for all of the missing inputs.

How do I use jQuery to omit the "Select All" check box from the list of elements sent to the server?

When the "Select All" check box is used, it also sends that check box and it's value to the server. How do I remove or omit it from the node list before sending it to the server using jQuery?
Thank You.
The simplest way would be to not give it a name :)
<input type="checkbox" />
You're looking for the remove function:
$('#someId').remove();
However, it will not do anything if the user has Javascript disabled.
I highly recommend that you change the server-side code to ignore that checkbox.
Try this:
$(".checkbox :not[id=chkcheckAll]").each(function(){//what needs to be done});
Assuming the id for Check all checkbox is chkCheckAll.
HTH

Categories

Resources