2

i would like to use spaces inside a data-chained tag, as i would like to combine customer names to customer adresses. is it possible? at the moment the script is looking for "Michael" or "Jackson", but not able to chain it to "Michael Jackson".

$(function() {

    /* For jquery.chained.js */
    $("#adress").chained("#customer");

 
    
    

  });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-chained/1.0.1/jquery.chained.min.js"></script>
<select id="customer" name="customer" class="form-control">
    <option value="">please select</option>
    <option value="Michael Jackson">Michael Jackson</option>    
    <option value="Katy Perry">Katy Perry</option>  
</select>

<select id="adress" name="adress" class="form-control">
    <option value="">please select</option>
  <option value="123 First Street, New York" data-chained="Michael Jackson">123 First Street, New York</option> 
  <option value="456 Last Street, San Francisco" data-chained="Katy Perry">456 Last Street, San Francisco</option>
Alon Eitan
  • 11,997
  • 8
  • 49
  • 58
  • What exactly is `jQuery.chained()`? Is it really a function or did you just make it up? – Alon Eitan Nov 04 '20 at 14:44
  • its a really useful function: https://github.com/tuupola/jquery_chained – chocwithstarfish Nov 04 '20 at 14:47
  • The problem isn't the spaces in the data attribute. If you look at the library's own page ([here](https://github.com/tuupola/jquery_chained)) you can see that it's very outdated. In fact, their own example no longer works at all: https://jsfiddle.net/w6fht2a5/. I would strongly suggest you find an alternative library, or build your own solution as relating select elements is quite straightforward. – Rory McCrossan Nov 04 '20 at 14:47
  • 2
    That is very important that you specify the libraries you're using - I fixed your fiddle and added the necessary external libraries for it to work – Alon Eitan Nov 04 '20 at 14:50
  • it works when i just use the first name. the space is causing the problem. – chocwithstarfish Nov 04 '20 at 14:51
  • @RoryMcCrossan not sure what the `chained` is *supposed* to do, but your fiddle (copied from the page exactly) wasn't working simply because it was missing a close comment `*/` https://jsfiddle.net/kbphaxum/ - it does ... *something* ??? – freedomn-m Nov 04 '20 at 16:20
  • @freedomn-m you're right, my mistake. However it's still broken. From reading the documentation it's supposed to filter the options of the second select based on the value selected from the first one – Rory McCrossan Nov 04 '20 at 16:37
  • @RoryMcCrossan agreed - doesn't seem to work – freedomn-m Nov 04 '20 at 16:48

0 Answers0