Loading ...
Sorry, an error occurred while loading the content.

Problem using form values in Queries

Expand Messages
  • chrish_taffydb
    Hi I have a basic form with some tick boxes which I want to use as product selections. My javascript knowledge is fairly basic so I imagine that I am doing
    Message 1 of 2 , Apr 1, 2013
    • 0 Attachment
      Hi

      I have a basic form with some tick boxes which I want to use as product selections. My javascript knowledge is fairly basic so I imagine that I am doing something obviously wrong. Any help would be greatly appreciated because I have been going round in circles for hours with this ....


      ------------ code start ------------

      <html>
      <head>
      <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
      <script src="taffy-min.js"></script>
      <script>
      var selections = TAFFY();
      var attributes = TAFFY();
      var products = TAFFY();

      attributes.insert({attribute_group:'Vendor',attribute_id:1,label:'AMD'});
      attributes.insert({attribute_group:'Vendor',attribute_id:2,label:'Intel'});
      attributes.insert({attribute_group:'Socket',attribute_id:3,label:'AMD AM3'});
      attributes.insert({attribute_group:'Socket',attribute_id:4,label:'AMD AM3+'});

      products.insert({Vendor:2,Socket:2,ID:1});
      products.insert({Vendor:2,Socket:1,ID:2});
      products.insert({Vendor:2,Socket:1,ID:3});
      products.insert({Vendor:1,Socket:2,ID:4});

      $(document).ready(function () {

      $('.attribute').click(function () {

      var key = $(this).val();
      var parts = key.split('_');
      var query = '';

      if($(this).prop('checked')) {
      selections.insert({id:parts[1],name:parts[0]});
      } else {
      selections({id:parts[1],name:parts[0]}).remove();
      }

      selections().each(function (r) {

      //query += {r.name:r.id}; //this raises an error

      if(r.name == 'Vendor')
      query += {Vendor:r.id};

      else if(r.name == 'Socket')
      query += {Socket:r.id};
      });

      alert('stringify ' + JSON.stringify(query));

      alert ('prodIDs (dynamic) ' + products(query).select("ID")); //this doesn't work

      alert ('prodIDs (manual) ' + products({Vendor:2},{Socket:1}).select("ID"));
      // this works doing it manually, answer: ProdIDs 2,3
      });
      });
      </script>
      </head>
      <body>
      <form>
      <h3>Select a vendor</h3>

      <label for="Vendor_1">AMD</label>
      <input class="attribute" type="checkbox" value="Vendor_1" name="Vendor" />

      <label for="Vendor_2">Intel</label>
      <input class="attribute" type="checkbox" value="Vendor_2" name="Vendor" />

      <h3>Select a socket</h3>

      <label for="Socket_3">AMD AM3</label>
      <input class="attribute" type="checkbox" value="Socket_3" name="Socket" />

      <label for="Socket_4">AMD AM3+</label>
      <input class="attribute" type="checkbox" value="Socket_4" name="Socket" />
      </form>
      </body>
      </html>
    • kayteemunnie
      Hi, I am also looking for help with inserting checkbox values into my taffydb tables. Have you resolved this ? Thanks,
      Message 2 of 2 , Apr 3, 2014
      • 0 Attachment
        Hi, I am also looking for help with inserting checkbox values into my taffydb tables. Have you resolved this ?

        Thanks,
      Your message has been successfully submitted and would be delivered to recipients shortly.