0

This is an edit check on a multiple select field for a search form.

When a selection is made in the multiple select field and the form is submitted, the empty() function logs "USER MADE A SELECTION", that part works. However, if no selection is made, the empty() function does not log "NO SELECTION MADE". If no selection is made in the field, won't the variables citySelectedValue and citySelectedHTML be null and/or undefined? I believe the script I found checks for that? Not sure if I setup my jsfiddle correctly. If not, let me know and I'll fix it:

https://jsfiddle.net/ibuprofen/077qxk01/

Thomas
  • 117
  • 1
  • 10

1 Answers1

1

Try this code: https://jsfiddle.net/077qxk01/31/

This function is rsponsible for getting proper information about selected options. You could even extract their values or text:

function getSelectValues(select) {
  var result = [];
  var options = select && select.options;
  var opt;

  for (var i=0, iLen=options.length; i<iLen; i++) {
    opt = options[i];

    if (opt.selected) {
      result.push(opt.value || opt.text);
    }
  }
  return result;
}    

As for JSFiddle - i would recommend sticking to this: JavaScript not running on jsfiddle.net guidelines when trying to use "onclick" attribute :)

Community
  • 1
  • 1
SzybkiSasza
  • 1,591
  • 12
  • 27
  • Well, what you posted works like I thought the other would so I'll go with that. Also read through the link you posted and I'll follow that from now on. Thanks for the help, I can now get back to work. – Thomas Jun 02 '15 at 22:34