Rectangle 27 7

In some cases the checkbox may be selected by default. If you want to restore default selection rather than set as unselected, compare the defaultChecked property.

        this.checked = item.defaultChecked; 

How to reset all checkboxes using jquery or javascript? - Stack Overfl...

javascript jquery checkbox
Rectangle 27 7

In some cases the checkbox may be selected by default. If you want to restore default selection rather than set as unselected, compare the defaultChecked property.

        this.checked = item.defaultChecked; 

javascript - How to reset all checkboxes using jQuery or pure JS? - St...

javascript jquery checkbox
Rectangle 27 7

In some cases the checkbox may be selected by default. If you want to restore default selection rather than set as unselected, compare the defaultChecked property.

        this.checked = item.defaultChecked; 

javascript - How to reset all checkboxes using jQuery or pure JS? - St...

javascript jquery checkbox
Rectangle 27 7

As described in the docs, the Eternicode version of bootstrap-datepicker adds three attributes to the changeDate event that can be used for accessing the newly selected date. You'll be interested in either the .date property (which points to the actual date object representing the selected date) or the .format method, which you can use to get the date as a string.

Assuming the simplest case (where you have a single picker and you want to get the date as a string in the same format that you initialised the datepicker with), you'll just want to call .format() with no arguments:

$('#calendar').on('changeDate', function(event) {

Actually your fiddle contains different code. It calls .datepicker() before .on() - this is essential.

@buffjape well, sure - if you don't call .datepicker() at some point in the code, then you don't have a datepicker. But note that the .datepicker() call just returns the jQuery collection it was called on for chaining, not any kind of special datepicker object - so you don't need to call .on() specifically on the result of the .datepicker() call, you just need to have called .datepicker somewhere in your code. See for an illustration of this.

javascript - How to get the changed date from bootstrap-datepicker - S...

javascript jquery twitter-bootstrap bootstrap-datepicker
Rectangle 27 0

I dont know of a way to do that, rather than create your own custom validation attribute. There are more than a few ways to achieve that, but the approach I would use is to assign the attribute to all included properties and then use reflection to check if at least one of them has a value (identifying them by checking if they have the attribute). In the IsValid method of the ValidationAttribute you have all the access to the instance and type so reflection should do the trick. Also, if you want client side validation to work, you can extend the IClientValidatable, send the values of all required fields through the GetClientValidationRules() rule parameters, and finally write your own javascript function to execute the rule. It sounds as an awful lot of work and it is, but if you make it flexible enough it should be reusable. Adding and removing the attribute to a property in a class should include/exclude a field from the validation list (if I may call it like that).

Here is where I got more familiar with that stuff when I had similar issues: Conditional Validation in ASP MVC

c# - ASP.NET Validator for multiple fields - Stack Overflow

c# validation
Rectangle 27 0

This will degrade nicely if there's no JavaScript. Use id and for attributes to link up the label and radiobutton so that when the image is selected, the corresponding radiobutton will be filled. This is important because we'll need to hide the actual radiobutton using JavaScript. Now for some jQuery goodness. First off, creating the CSS we'll need:

The reason why we're not using display: none here is for accessibility reasons. See: for a live demo, with something more fancy.

The only thing you seem to be missing here is setting the appropriate input's checked value when the corresponding image is clicked.

@Rob clicking on labels would check the appropriate inputs - no JavaScript needed. You can comment out the first line of the JavaScript code to see this.

Ah, you're right! Thanks. I modified your example slightly to make the image the clickable thing, which would be why I saw that behavior. My bad.

html - How do I style radio buttons with images - laughing smiley for ...

html css forms
Rectangle 27 0

When an assignment occurs within strict mode code, its LeftHandSide must not evaluate to an unresolvable reference. If it does a ReferenceError exception is thrown upon assignment. The LeftHandSide also may not be a reference to a data property with the attribute value {[[Writable]]:false}, to an accessor property with the attribute value {[[Set]]:undefined}, nor to a non-existent property of an object whose [[Extensible]] internal property has the value false. In these cases a TypeError exception is thrown.

In your sample code, the left-hand side of an = expression is, in fact, a reference to a data property with the "writable" flag set to false.

Now I am somewhat sympathetic to the notion that it shouldn't apply to inherited properties, but I can see that there may be a strong counter-argument. That the object literal allows the property to be created as an "own" property of the new "sugar" object certainly seems odd.

edit for clarity, the issue here is that assignment to an object property is always about assigning to an "own" property of the object. Assignments don't affect properties up the inheritance chain. Thus, the question posed involves the following apparent contradiction: if a property from the Object prototype with the "writable" flag set to false prevents assignment to that property name on existing objects, why is it that assignment to that property succeeds in the course of evaluation of an object literal?

There could be a nice rationale for this, or it could be a bug. Both V8 and whatever the Firefox runtime is currently called (something-monkey I guess) act the same way.

Do you have any thoughts about why the is treated differently?

@Tom Well that's what makes me think that there's something fishy going on. However, I don't know which behavior to call "wrong" :)

@Tom it could be that the "sugar" thing works because of the way that object literal expressions are defined. When properties are defined that way, the spec explicitly says that [[DefineOwnProperty]] is called.

javascript - Weird behaviour with 'use strict' and read only propertie...

javascript node.js use-strict defineproperty
Rectangle 27 0

Instead of altering the CSS rule directly, you can give the element another class corresponding to another rule: { display: block; }[data-position="left"] { display: block; }

That rule should go after the existing rule to ensure that a "slide" element that also has the "active" class will be visible.

You'd add the class in JavaScript with


This works very well and adds a active class: <div id="content" class="slide active" data-position="left">. Unfortunately I tried this method before posting here and it doesn't change too much. I forgot to mention that I have a large js code and changing the .slide[data-position="left" is a must. I know it sounds awkward. The problem is if I manually change the state of displayto block everything works. Thank you for your help!

@user3095180 if you could describe more about your situation (preferably by extending your question), it would be easier to give workable suggestions. You haven't really explained why you are forced to find a way to modify the CSS.

Ok. I want to add a menu to a slide. the menu works perfectly but when I'm moving it into the <div class="slide" data-position="left"></div> it disappears. The slide has this data-position that masks the slide when it's closed. When I open the slide the display must change to block. If I manually change this property everything works. That's why I need to know if I can do it in javascript.

jquery - Change the state of a property from CSS class that has a attr...

javascript jquery html css css3
Rectangle 27 0

Dont save objects as JSON strings in the html tag property value. Use the data() method instead.

$('input[type="button"]').data({ option1: 'o1', option2: 'o2' });

option1 would need to be a plugin in order to be chained on to the data method (or any jquery method for that matter). You would need tomething like this:

jQuery.fn.option1 = function () {


   return this;

why can't i save objects as JSON strings? also i don't want to generate this data using JS b/c it will be highly variable across my app and i've already spent the time to generate it with server side code (logic is wired in my mysql database)

@timpeterson Well, html tags property values should be wrapped with double quotes. JSON strings should be as well. So I wouldnt recommend it. You would end up with either invalid html or json.

@timpeterson How are you fetching the data from the server? By ajax? Or are you just printing it directly in to the html? And what serverside language are you using?

@timpeterson Sorry about the delay, i went for lunch. Check out the fiddle that i posted. Is this what you need?

@timpeterson If you want to write a custom jquery method (aka plugin), thats how its done (In other words, as long as you want to use your method directly on the jquery object). If you dont want to do that you could extract the data object and pass it to your regular function and handle it there.

jquery - How to use a button's "data-" attribute to call a selected Ja...

javascript jquery html json custom-data-attribute
Rectangle 27 0

A div will have no attribute of width. It may have a CSS style property of width, which you can retrieve using .css('width'), but you may also be interested in outerWidth() or innerWidth() or width() which return the width computed by JavaScript.

$().ready(function() {
function doLayout() {
    var $width = $("#sidebar").css("width");
    $("#content").css("left", width);

A good explanation of how the above mentioned width methods differ can be read in the documentation, but simply;


jQuery: get div-width after document is ready and rendered - Stack Ove...

Rectangle 27 0

The answer from m59 is correct -- you should use a deep copy of the "tree-data" if you need 2 trees. The tree-data that you supply is not just the definition of the tree -- it will also be used to track it's state -- the tree adds an "expanded" attribute and a "selected" attribute to each branch. So, if you share tree data, then "expanded" states are also shared. If you want 2 trees with separate state, then you need separate tree-data.

A better approach might be to keep the "tree-data" separate from your original data, whatever it is. Use a function that loops over your original data, and creates the "tree-data" from it.

If you want to have 2 trees represent a common, shared set of data, then you could use the "" attributes of the branches to refer back to elements of your original data. That is, have separate "tree data" for each tree, but have branches in both trees point to some shared data.

Suppose, for example that you have a list of "People", and you want to create 2 trees that both represent that same list of people.

First, write a function that loops over your list of people, and produces a new list of tree branches ( the "tree data" ). For each branch, set the "" to point to the original "person" object from your list of people.

Now, run your function twice, to produce 2 separate sets of "tree data". The result is 2 trees with separate state, but with "" on both trees referencing the same shared data.

Note that you must be careful about using a "deep copy" if you are also using "" -- you probably don't want to deep copy the branch data ( in the example, that would create a copy of each "Person" object referenced by, which is not what you want -- you want a shared reference )

javascript - Array reference is reused instead of cloned/copied - mult...

javascript angularjs twitter-bootstrap tree angularjs-directive
Rectangle 27 0

I agree with @coder. One slight change to his code is removing of previously selected entry. If user has already selected an option and then you want to change it to something else using jquery (unless your select box has attribute "multiple" set), you will have to un-select the user's selection option.

$("#myselect option:eq(1)").attr("selected", "selected").siblings("option").removeAttr("selected");

as mentioned by @cletus.

javascript - Use jQuery select an option? - Stack Overflow

javascript jquery
Rectangle 27 0

JQMIGRATE: jQuery.fn.attr('selected') may use property instead of attr...

Cause: Prior to jQuery 1.9, $().attr("checked") etc. would sometimes use the checked|selected property instead of the attribute when interacting with non-XML elements, despite the fact that browsers and the HTML specifications allow the properties (current state) to differ from the attributes (initial/default state). This was a holdover from earlier versions of jQuery that did not offer $().prop.

Solution: Boolean properties should generally not be passed to $().attr at all; replace with $().prop unless you truly intend to update the underlying HTML attribute.

The difference between attributes and properties can be important in specific situations. Before jQuery 1.6, the .attr() method sometimes took property values into account when retrieving some attributes, which could cause inconsistent behavior. As of jQuery 1.6, the .prop() method provides a way to explicitly retrieve property values, while .attr() retrieves attributes.

i read out the document, but still i couldn't get a clear picture about this warning. It would be more helpful if i can get answers from good examples.

@SasiDunston check the edit, added more resources, it's a deeply explained change

javascript - JQMIGRATE: jQuery.fn.attr('selected') may use property in...

javascript jquery
Rectangle 27 0

I had a similar issue with rich:select. To resolve it, we had to change to h:selectOneMenu and add ajax capability for the onchange javascript function. Plus, when you're using the ajax approach, you should use valueChangeListener in your h:selectOneMenu to set the selected value instead of the value attribute.

I'll let you a sample

<h:selectOneMenu id="select1" maxListHeight="100" 
    enableManualInput="true" defaultLabel="Type here"
    <f:selectItems value="#{carBean.lstCompany}"></f:selectItems>
    <a4j:ajax id="ajax1" queueId="queue1" execute="@form"
        render="select2, errorText" event="selectitem"

In your ManagedBean, you should have a code like this:

public class CarBean implements Serializable {
    private String companyName;
    //getters and setter...
    //constructor and other functions
    public void valueChangeMethod(ValueChangeEvent e){
        companyName = (String)e.getNewValue();

There is a post about this issue in the RichFaces Forum. Additionally, a BalusC (JSF expert) blog entry about populating child menu's.

Hello Luiggi. I tried your suggestion 3 day ago. I still cannot use 2 ajax event yet. The problem appear when I use 2 <a4j:ajax/> and unfortunately with both <rich:select and html select, only one ajax active.

jsf - two rich:ajax conflict problems (in 3 rich:select controls) - St...

jsf jsf-2 richfaces
Rectangle 27 0

Use the checkbox properties instead of their attributes

$(function () {
    $('#selectall').on('click', function() {
        $('.selectedId').prop('checked', this.checked);       

javascript - reselecting all checkboxes using jquery causing weird act...

javascript jquery html checkbox onclick
Rectangle 27 0

I see that the answer has been selected, but I don't agree with the solution, though it does work. I wouldn't characterize this as a flaw with AS3 as this would happen the same way with Javascript, also based on ECMAScript. In any case, you can avoid the problem altogether by just creating a property for BasicGameButton that holds the value of n. Also, instead of adding a listener for every button, just create a single listener on the button container that listens for the mouse click (a mouse click "bubbles" up to a parent display object) and gets the clicked button using the event target.

/* inside the loop */
btt.n = n;

/* parent listener you only have to create once */
buttonContainer.addEventListener(MouseEvent.CLICK, onClick);

function onClick(e:Event):void {

BasicGameButton wasn't a class, rather an instance of SimpleButton within the flash library and I was hoping to avoid having to make a class specifically for it. As such, btt.n = n doesn't work (unless theres a way to externally create new variables). Also, the actual code Im using is slightly more complex than the code I posted above, so I cant really use a eventListener on parent, since there will be multiple buttons and whatnot going on in the background. I appreciate the input nevertheless.

flash - Creating a function within a loop (pointers?) - Stack Overflow

flash actionscript-3 actionscript flash-cs4
Rectangle 27 0

If you had passed a model into the view, it would have displayed that model. If you do not pass a model, the view simply uses your model class to create the controls. In this case it is creating labels, textboxes and validation for all the properties. It uses those lambda expressions in LabelFor (xxxFor) as Expression Trees and analyses your class. It analyses and looks for things like: In the model you may have used a Display("Full Name") attribute for Name property, therefore it will conclude you want to show "Full Name" in label instead of "Name". It creates validation javascript in the same manner.

Therefore, in order to use the expression tree given in lambdas, it does not need an instance of the model.

c# - How does MVC framework assign model to a view while returning it ...

c# model-binding strongly-typed-view
Rectangle 27 0

Each time you read some property of Python object, method __getattribute__ is called, so you can overload it and completely control access to object's attributes. Nevertheless, for your task a bit different function - __getattr__ - may be used. In contrast to __getattribute__ it is called only if normal lookup for an attribute failed, i.e. at the same time, as prototype lookup in JavaScript starts. Here's usage:

def __getattr__(self, name):
    if hasattr(prototype, name)
        return getattr(prototype, name)
        raise AttributeError

Nice but why do you need the if statement? Why not just make the whole body return getattr(prototype, name)? Are you worried about the AttributeError message in that case?

javascript - Prototypal programming in Python - Stack Overflow

javascript python inheritance prototype prototypal-inheritance
Rectangle 27 0

Use this code to reset all selection fields to the default option, where the attribute selected is defined.

<select id="name1" >
    <option value="1">Text 1</option>
    <option value="2" selected="selected" >Default Text 2</option>
    <option value="3">Text 3</option>
<select id="name2" >
    <option value="1">Text 1</option>
    <option value="2">Text 2</option>
    <option value="3" selected="selected" >Default Text 3</option>
    $('select').each( function() {
        $(this).val( $(this).find("option[selected]").val() );

javascript - How to set the first option on a select box using jQuery?...

javascript jquery
Rectangle 27 0

The val() is a jQuery method which can't use with DOM object. To get value use value property of the element instead.

function getValue(ele) {
  // with jQuery it should be
  // alert($(ele).val());
function getValue(ele) {

Since you are tagged jQuery in your question use change() event handler, Inside the change event callback this refers to the corresponding dom object.

// select element with the name  attribute equals 
// selector can be used and then bind event handler
$('[name="a[]"]').change(function() {
  // get the value
<script src=""></script>
<select name="a[]">
  <option value="11">11</option>
  <option value="12">12</option>
<select name="a[]">
  <option value="21">21</option>
  <option value="22">22</option>

javascript - Get the value of selected option using jQuery - Stack Ove...

javascript jquery