1

I have a problem, I have been working on some jquery to set the quantity text box to display 25 or more. It checks if the wording personalisation has an empty string, if it doesnt them apply the 25 quantity as its obviously a kit product and personalised.

The crucial part for kit products is:

if (parseInt($("#kitProduct #Quantity").val()) < 25) {
    $("#kitProduct #Quantity").attr("value", "25");

It knows its a kit product because i have a div.id wrapped around the page called Kit Product.

My problem is that i need to override this kit product code for certain products. I thought the best way to do this as aquick fix would be to check for the contents of a div, eg:

<div class="ProductNameText">Exclusive Handmade Box</div>

If Exclusive Handmade Box is found then allow the user to enter a quantity of 1 or more into the text box.

I have tried the following code:

quantity = $('div.ProductNameText').text().match(/Exclusive Handmade Box/g).length;
       if(quantity)
         {
          $("#kitProduct #Quantity").attr("value", quantity);
          $("#kitProduct #Quantity").keypress(function(){

          var quantity = parseInt($.trim($(this).val()));
          if( quantity < 1) {
             $(this).val('1');
          } else {
             $(this).val(quantity);
         }

But this will only ever force 1. I am really lost now, ive explained as best as i can and below is a cut down example of the page within a jsfiddle.

Really hope you can help?

More infomation:

For the most part Kit products are defined in an xml package which is applyed to a kit product in the admin section. However i have a few products which are still products but dont require 25 to be put into the quantity.

At the moment the jquery checks for a text area box because if the user adds a personalisation into that it means they are wanting a kit product therefore min quantity is 25.

But i have a product i want to check based on its div contents that i want to have as 1 or more...

so i should be able to enter 1-25 into the box without my current code saying oppps you entered less than 24 so im going to change it back to the min kit product quantity..

if you try the jsfiddle you can see that it wont let you put in a value of say 3? thats the problem.

http://jsfiddle.net/FB5MQ/3/

PD24
  • 754
  • 6
  • 16
  • 37

1 Answers1

0

You should just have a variable minimum in the "crucial part for kit products" code:

var minValue = 25;
if ($('div.ProductNameText').text().match(/Exclusive Handmade Box/)) {
    minValue = 1;
}

if (parseInt($("#kitProduct #Quantity").val(), 10) < minValue) {
    $("#kitProduct #Quantity").prop("value", minValue);
    // rest of code...
David Hu
  • 3,076
  • 24
  • 26
  • If you try the jsfiddle i made and attempt to enter 2 in the box and click in the white space. It forces it back to 25. This is wrong. I need to be able to enter less than 25 and more than 25 also. But i need to override the kit products code as its needed elsewhere. – PD24 Nov 24 '11 at 10:10
  • @PD24 I've re-read the question and changed my answer. I'm still not quite sure if I completely understood your question though. – David Hu Nov 24 '11 at 10:40
  • can you ammend the jsfiddle please? Am i able to enter less than 25 into the box? – PD24 Nov 24 '11 at 10:55