JQuery multi select check box dropdown is not unchecked on browser refresh? - javascript

I am using JQuery multiselect checkbox dropdown.
$("select").multiselect();
i have two divs in the same html page. in both the divs i have multi select checkbox dropdown.
on browser refresh, the values checked are not unchecked.To solve the issue, i kept below the code.
window.onbeforeunload = function(){
$("select").multiselect("uncheckAll");
};
But the problem is above code unchecks the values of multiselect checkbox only in one DIV. in other DIV's multiselect check box the values are not unchecked. How can i solve the issue?
Thanks!

Try using proper selectors for the select boxes ie) give seperate ids and perform you function of checking or unchecking.

try
$("select").each(function(){
$(this).multiselect("uncheckAll");
});

Related

Can't select option after deselecting it with JQuery or in UI

In a select tag with multiple attribute.
When I was using old multi-select JQuery plugin, I find out that I can't select previously deselected options. Actually, I can see that they are selected in UI that created with that plugin, but they were not selected when I submit the form.
Then, I tried to remove selection and select it again from the console without any JQuery plugin.
After deselecting the selection by removing attribute selected from option:
document.getElementById('option_1').removeAttribute('selected');
I was able to select that option again without any problem using JS code:
document.getElementById('option_1').setAttribute('selected', '');
But, when I tried to remove the selected attribute with JQuery removeAttr or prop:
$("#option_1").removeAttr('selected');
$("#option_1").prop('selected',false);
It removes the selection, but I can't select that same option again. Tried both JQuery and JS:
$("#option_1").attr('selected','selected');
document.getElementById('option_1').setAttribute('selected', '');
Again, I can't select the same option with code when I manually deselect option with ctrl+(right-click to selected option)
1. Why it happens?
2. I really liked that plugin and tried to change JQuery code .removeAttr('selected'); to JS code .removeAttribute('selected');. But I got an error. How can I fix that?

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.

How to disable dropdown if no option selected on page load using jquery?

I have table with many dropdowns in it. I want to disable the dropdown if any option isn't selected on form load.
I tried this and it disable all dropdowns.
jQuery("Select.form-component").prop("disabled",true);
I want to disable only empty value dropdowns on form load using jquery
This will work:
$('select.form-component[value=""]').prop("disabled",true);
You can try:
$('#dropDownId').attr('disabled', true);
or Javascript
document.getElementById("mySelect").disabled=true;

change form based on drop down menu selection

I'm having trouble finding javascript, HTML and/or CSS code that'll change the form based on the drop down menu. For example, the form is for adding a property and the drop down menu selections are single family, condo, apartment but they each have their own set of text boxes, menus and radio buttons. How can I achieve this?
What I have understand from your query is that , you have a from with some fields and you have a dropdown and you want that when ever your change selection in dropdown the form fields values must change accordingly right ?
If that is the issue , then it is very simple , first catch onSelectionChange event of dropdown and try to get selected value and once you get the selected value fill form fields by accessing them accordingly in a condition.Thanks
So I actually already had a piece of code I was fumbling with (http://jsfiddle.net/CYzsY/) for this question and it looks like its not working for me because its based on jQuery 1.7.1 and I'm linking to 1.10.2 in my code. Will make a new post accordingly. Thanks everyone!

Dropdown Check List Radio Unselect

I use this very nice plugin in my project called jQuery Dropdown Check List (https://code.google.com/p/dropdown-check-list/) specifically one of example which is named: 'Single select with radio buttons instead of checkboxes'.
One big problem with this example is that I am not able to (I was trying to do this by jQuery) set radio button unchecked. I was using for example:
$("input:radio").attr("checked", false);
Or
$("input:radio").removeAttr("checked");
And unfortunately nothing. Can anyone give some advice how fix this thing?
Try this:
- For check:
$("input:checkbox").attr("checked", "checked");
or
$("input:checkbox").prop('checked', true);
-For uncheck:
$("input:checkbox").removeAttr("checked");
or
$("input:checkbox").prop('checked', false);
I tried both methods in the demo page(http://dropdown-check-list.googlecode.com/svn/trunk/doc/dropdownchecklist.html) for the "Single select with radio buttons instead of checkboxes", and turns out to be fine: the selected radio button has removed. However, the value stays in the span because remove selected radio cannot remove selected value.
My suggestion is that after you uncheck the radio, also set a html space to the span, it removes the selected value and also keep the height of its container.
This plugin uses checkbox not radio inputs so you must use $('input:checkbox') or $('input[type="checkbox"]') as your selector!
Click here to see a demo!

Categories

Resources