Avatar of peter-cooper

asked on 

How do I Enable submit button only if listbox has items

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

PHPjQueryHTMLJavaScriptMySQL Server

Avatar of undefined
Last Comment

8/22/2022 - Mon