Jump to content

disable button if not selected value works only on 1st selection - after deslect it stil works


roberto68
 Share

Recommended Posts

I've form where htere are 4 multiselect dropdowns I use code like this ("dropdowns" is the id of that form) and there's nothing else in that form just those multiselects.

	$(".submit").attr('disabled','disabled'); // defaultne disabled	$("#dropdowns").change(function() {  // alebo cekovat kazdy dd zvlast 	if($(this).val()===""){            $(".submit").removeAttr('disabled'); 			} else {	$(".submit").attr('disabled','disabled');				}      });

maybe should I chcek all 4 DDs inside the .change(function ??? instead of if =($this)

for (i=1; i<4; i++) { if($("#dd"+i).val()===""){ ....

the ids are dd1....dd4. amd one littel question - I've seen somwhere .fliter(:selected) or smth like that - cause I've little probelms with this form retrieving on another page - so I'd like to post it one form - so when user clicks submit another multiselect = another form is created at that time actualy that newly created is posted

Edited by roberto68
Link to comment
Share on other sites

and here's html : just hte 1st dropwdown but it goes on like that

	<form name="dropdowns" id="dropdowns">    	<div class="box">        	<img src="images/pic1.jpg" alt="pic1">            <h2>education</h2> <label for='educationForm'>select what you wanna learn<br><div align="center" class="drop">            <a href="#" class="dropdown-toggle">select</a><select class="dropdown-menu" multiple="multiple" name="mydropdown1[]" id="dd1"><label="education"><option value="1">IT-programing</option><option value="2">IT-sys_admin</option><option value="3">IT</option><option value="4">science</option><option value="5">electronic engineering</option><option value="6">math&physics</option><option value="7">mechanical_engineering</option></select></label></div></label>
Edited by roberto68
Link to comment
Share on other sites

You're selector (#dropdowns) is only looking for changes on the <form>. Target the actual <select> elements instead, either by tag or by class.

Link to comment
Share on other sites

so I changed

$("#dropdowns").change(function() { 

for (every DD has that class)

$(".dropdown-menu").change(function() {  

so it targets every DD but the buttons stays disabled all the time. And my last point - why are the dropdowns rolled out on page load - I want them to be hidden and show only on the click - which it does right now but on the page load it is "rolled out" not hidden as I excpect it to be

right now it is like that

// $("select").removeClass("dropdown-menu");    $('.dropdown-toggle').click(function(){       $('.dropdown-menu').toggle();   });

when I uncoment the 1st line DD are hidden onload but then they are not working anymore

Edited by roberto68
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...