troubleshooting Question

How do I Enable submit button only if listbox has items

Avatar of peter-cooper
peter-cooper asked on
PHPjQueryHTMLJavaScriptMySQL Server
4 Comments1 Solution223 ViewsLast Modified:
initially i have the submit disabled so users cannot submit an empty list. Is there way with my existing code to detect if a list has items and enable the submit button. However if a user removes items then make it false .

I am using jquery to populate a listbox which a contributor helped me with and wodering if that could be modified to check for items in a list and enable the submit button.



	$conn = mysql_connect("localhost","root","");
	$result = mysql_query("SELECT * FROM boxes where department = '{$_GET['dept']}' ORDER BY custref ASC");
	<select name="boxdest[]" id="boxdest" size="7" multiple="multiple">

	while($row = mysql_fetch_array($result)) {
	<option value="<?php echo $row["custref"];?>"><?php echo $row["custref"];?></option>
	<span style="display: inline-block; width: 70px; height: 82px; padding-left: 10px; padding-right: 10px; vertical-align: top;margin-top:35px;">
          <button class="btn btn-primary switch-item" data-src="boxdest" data-dst="boxdest2">&gt;</button>
    	  <button class="btn btn-primary switch-item" data-dst="boxdest" data-src="boxdest2">&lt;</button>
	  <select name="boxdest2[]" id="boxdest2" size="7" multiple="multiple"></select>

Open in new window


		$(function () {
			$('.switch-item').click(function (e) {
				var src = $(this).data('src');
				var dst = $(this).data('dst');
				var sel = $('#' + src + ' option:selected').detach();
				$('#' + dst).append(sel);
			$('form').submit(function () {
				$('#boxdest2 option').prop({
					selected: true

Open in new window


Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 4 Comments.
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>


Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 4 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004