-1

I want to add off option value in my page

For example, you come in my shop page and choose a package, I want to add an option field for the Discount and when you enter a text that is available on s.txt you receive a discount offer.

For example, you enter a StackOverflow code and in s.txt:

stackoverflow--20

Then the price will be reduced by %20 and displayed.

My source code follows.

JavaScript:

$("#payBtn").click(function() {
  $("#count").html($("#member").val());
  var price = $("#member").val();
  price = price * 5;
  location.href = 'https://zarinp.al/levicoder/' + price;
    }); 
$("#name").keyup(function() {
  $("#payerName").html($("#name").val());
});
$("#channelInput").keyup(function() {
  $("#channel").html($("#channelInput").val());
});
$("#discount").keyup(function() {
  $("#disdis").html($("#discount").val());
});
$("#member").click(function() {
  $("#count").html($("#member").val());
  var price = $("#member").val();
  price = price * 5;
  $("#amount").html(price);
});

Html:

<div class="box shadow_box purchase_cm_box" >
        <h4>Order</h4>
        <hr>
        <input type="text" class="form-control" id="name" placeholder="Your name"><br>
        <input type="text" class="form-control" id="channelInput" placeholder="Your Id"><br>
        <input type="text" class="form-control" id="discount" placeholder="discount code"><br>
        <div class="form-group">
         <select class="form-control" id="member">
           <option value="9000">9000 Value</option>
<option value="2000">2000 Value</option>



         </select>
         <br>
        </div>
      </div>

<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12 pull-left" id="leftmenu">
      <div class="box shadow_box purchase_cm_box" >
          <h4>Factor</h4>
        <hr>
        Your Name : <label id="payerName">don't entered</label><br>
        Your id : <label id="channel"></label><br>
        discount code : <label id="disdis"></label><br>
        Pay Count
        <label id="amount">7,000</label>
         $
        <br><br>
                <button class="getBtn" id="payBtn">Pay</button><br>

        <p id="payStatus"></p>
      </div>
  </div>
Omid Nikrah
  • 2,444
  • 3
  • 15
  • 30
LeVi
  • 9
  • 4
  • I've tried to understand your question, but I'm having trouble. I understand that you want to add an – holaymolay Oct 07 '18 at 20:25
  • Hi Mr.yes and if `stackoverflow` Code exists On S.txt Price Will Be * 20%(F.E If stackoverflow--30 = Price * 30%) – LeVi Oct 07 '18 at 21:28
  • one more question, do you have the freedom to format `s.txt` differently? If yes, why not format it with JSON? That'd give you a more structured, information-dense way of storing your coupon codes. – holaymolay Oct 07 '18 at 23:14
  • I did not catch your point because i'm noob in js and need help;( – LeVi Oct 08 '18 at 04:07
  • Look Bro, I Need A Code-> Check Discount Option And If Entered Text Exists On S.txt,explode it With `--` And do `price * exploded number` . For Example if code is Stack and in s.txt is -> Stack--20 , do `price*20` – LeVi Oct 08 '18 at 10:10

1 Answers1

0

I tried not to officially answer this question because I am unsure what LeVi needs. But as a result of our conversation in the comments, I was asked to provide code.

Here's my best guess of what LeVi is asking:

let inputCode = "stackoverflow"; 
let savedCode = "stackoverflow--20"; // derived from file s.txt

let splitSavedCode = savedCode.split('--'); // this will return ['stackoverflow', '20'] 

if( inputCode == splitSavedCode[0] ) { 
  // edited after further discussion in comments
  let discountPercentage = splitSavedCode[1] / 100;
  let discountAmount = price * discountPercentage;
  $('#discount').val(discountAmount);
} 
holaymolay
  • 520
  • 4
  • 17