Click here to Skip to main content
15,881,027 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Why doesn't this script work?

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span id="price_here" hidden="hidden">600</span><span id="sum_here">600</span> </button>◀<input type="number" value="1" onchange="check_qty($(this),1,100);" name="qty" id="qty" value="<? echo $qty ?>"></input>▶<button onclick="qplus('#qty', 100);" id="plus">^__i></button> <span id="sum_here1"></span>^__i id="mlus">

<script>
$('#price_here').each(function() {
     this.textContent *= 2;
});

function qminus(el, min) {
     var e = $(el);
     var compare = parseInt(e.val());
     var i = ((compare - 1) < min) ? min : compare - 1;
     e.val(i);
     show_price(i);
}
  function qplus(el, max) {
     var e = $(el);
     var compare = parseInt(e.val());
     var i = ((compare + 1) > max) ? max : compare + 1;
     e.val(i);
     show_price(i);
}
  function check_qty(el, min, max) {
     var compare = parseInt(el.val());
     if (compare < min) {
         el.val(min);
         alert(min + ' is minimal qty');
     }
     if (compare > max) {
         el.val(max);
         alert(max + ' is maximum qty');
     }
     show_price1(el.val());
}
  function show_price(ch) {
     var sum = $('#price_here').html() * ch,
           coeff = +ch > 1 ? 0.02 : 0;
     $('#sum_here').html(sum * (1 - coeff));
     $('#sum_here1').html(sum * coeff);
}
</script>


What I have tried:

<script>
$('#price_here').each(function() {
     this.textContent *= 2;
});

function qminus(el, min) {
     var e = $(el);
     var compare = parseInt(e.val());
     var i = ((compare - 1) < min) ? min : compare - 1;
     e.val(i);
     show_price(i);
}
  function qplus(el, max) {
     var e = $(el);
     var compare = parseInt(e.val());
     var i = ((compare + 1) > max) ? max : compare + 1;
     e.val(i);
     show_price(i);
}
  function check_qty(el, min, max) {
     var compare = parseInt(el.val());
     if (compare < min) {
         el.val(min);
         alert(min + ' is minimal qty');
     }
     if (compare > max) {
         el.val(max);
         alert(max + ' is maximum qty');
     }
     show_price1(el.val());
}
  function show_price(ch) {
     var sum = $('#price_here').html() * ch,
           coeff = +ch > 1 ? 0.02 : 0;
     $('#sum_here').html(sum * (1 - coeff));
     $('#sum_here1').html(sum * coeff);
}
</script>
Posted
Updated 17-Feb-24 2:50am
v2
Comments
OriginalGriff 17-Feb-24 5:22am    
And?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.

1 solution

Use ChatGPT to compare to two code sections and it will highlight that you haven't corrected all the initial problems in the original source code. It is one of ChatGPT's better functions as it isn't making up code, just comparing and working with the code rules.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900