2016-02-10 46 views
0

如何從HTML輸入值設定值成JSON

<script src="https://secure.na.tnspayments.com/checkout/version/33/checkout.js" 
 
     data-error="errorCallback" 
 
     data-cancel="cancelCallback"> 
 
</script> 
 

 
<script type="text/javascript"> 
 

 
    $(document).ready(function() { 
 
     $("#reference").val('@ViewBag.reference'); 
 
    }); 
 

 
    function errorCallback(error) { 
 
     console.log(JSON.stringify(error)); 
 
    } 
 
    function cancelCallback() { 
 
     console.log('Payment cancelled'); 
 
    } 
 
    
 

 
    
 
    Checkout.configure({ 
 
     merchant: 'TEST1', 
 
     order: { 
 
      amount: "10", 
 
      currency: 'MXN', 
 
      description: "Description", 
 
      id: "Reference" 
 
     }, 
 
     interaction: { 
 
      merchant: { 
 
       name: 'Operadora', 
 
       address: { 
 
        line1: 'Address 1', 
 
        line2: 'Address 2' 
 
       } 
 
      } 
 
     } 
 
    }); 
 

 
</script> 
 

 
<div class="container"> 
 

 
    <div class="row" style="background-color:#05AED9"> 
 
     <div style="text-align:center;"> 
 
      <h2><label style="font-size: 28px ! 
 

 
important;color:white;">@Resources.Resources.LabelPaymentData</label></h2> 
 
     </div> 
 
    </div> 
 
    <div class="row" style="background-color:lightgray;padding-left:5%; padding-right:5%;"> 
 
     <br /> 
 
      <div class="form-group"> 
 
       <label>@Resources.Resources.LabelAmount</label> 
 
       <input id="ammount" style="width:100px;" type="text" name="order.amount" 
 

 
value="0.00" class="form-control"> 
 
      </div> 
 
      <div class="form-group"> 
 
       <label>@Resources.Resources.LabelDescription</label> 
 
       <textarea id="description" style="height: 50px !Important;width: 500px;" 
 

 
name="transaction.reference" class="form-control"></textarea> 
 
      </div> 
 
      <div class="form-group"> 
 
       <label>@Resources.Resources.LabelReference</label> 
 
       <input id="reference" style="width:300px;" type="text" 
 

 
name="order.reference" class="form-control" disabled="disabled"> 
 
      </div> 
 
      <div class="form-group"> 
 
       <label>@Resources.Resources.LabelEmail</label> 
 
       <input style="width:300px;" type="text" name="customer.email" class="form- 
 

 
control"> 
 
      </div> 
 
      
 
     <input class="btn btn-info" type="button" value="@Resources.Resources.NavPayment" 
 

 
onclick="Checkout.showPaymentPage();" /> 
 
     <br /> 
 
    </div> 
 
</div>

當單擊按鈕調用Checkout.showPaymentPage()這個函數需要Checkout.configure()..這個答案是如何設置輸入值「ammount」到Checkout.Configure?金額:「10」像這樣的金額:$(「#ammount」)。val()..請提醒我沒有任何想法做到這一點或如何以其他方式做到這一點.. thans爲您的幫助

+0

我想這可能會幫助你http://stackoverflow.com/questions/1184624/convert-form-data-to-javascript-對象與-jquery的。您應該也可以將所有內容都包含在'

'標籤中。 –

+0

我需要更改金額:10與用戶在字段「ammount」中鍵入的值 –

+0

金額:$(「#ammount」).val()不起作用? – DanielVorph

回答

0

<script src="https://secure.na.tnspayments.com/checkout/version/33/checkout.js" 
 
     data-error="errorCallback" 
 
     data-cancel="cancelCallback"> 
 
</script> 
 

 
<script type="text/javascript"> 
 

 
    $(document).ready(function() { 
 
     $("#reference").val('@ViewBag.reference'); 
 

 
     $("#btn-payment").click(function() { 
 
         
 
      Checkout.configure({ 
 
       merchant: 'TEST1', 
 
       order: { 
 
        amount: $("#ammount").val(), 
 
        currency: 'MXN', 
 
        description: "Description", 
 
        id: "Reference" 
 
       }, 
 
       interaction: { 
 
        merchant: { 
 
         name: 'Operadora', 
 
         address: { 
 
          line1: 'Address 1', 
 
          line2: 'Address 2' 
 
         } 
 
        } 
 
       } 
 
      }); 
 

 
      Checkout.showPaymentPage(); 
 
     }); 
 

 
    }); 
 

 
    function errorCallback(error) { 
 
     console.log(JSON.stringify(error)); 
 
    } 
 
    function cancelCallback() { 
 
     console.log('Payment cancelled'); 
 
    } 
 
     
 
</script> 
 

 
<div class="container"> 
 

 
    <div class="row" style="background-color:#05AED9"> 
 
     <div style="text-align:center;"> 
 
      <h2><label style="font-size: 28px !important;color:white;">@Resources.Resources.LabelPaymentData</label></h2> 
 
     </div> 
 
    </div> 
 
    <div class="row" style="background-color:lightgray;padding-left:5%; padding-right:5%;"> 
 
     <br /> 
 
      <div class="form-group"> 
 
       <label>@Resources.Resources.LabelAmount</label> 
 
       <input id="ammount" style="width:100px;" type="text" name="order.amount" class="form-control"> 
 
      </div> 
 
      <div class="form-group"> 
 
       <label>@Resources.Resources.LabelDescription</label> 
 
       <textarea id="description" style="height: 50px !Important;width: 500px;" name="transaction.reference" class="form-control"></textarea> 
 
      </div> 
 
      <div class="form-group"> 
 
       <label>@Resources.Resources.LabelReference</label> 
 
       <input id="reference" style="width:300px;" type="text" name="order.reference" class="form-control" disabled="disabled"> 
 
      </div> 
 
      <div class="form-group"> 
 
       <label>@Resources.Resources.LabelEmail</label> 
 
       <input style="width:300px;" type="text" name="customer.email" class="form-control"> 
 
      </div> 
 
      
 
     <input id="btn-payment" class="btn btn-info" type="button" value="@Resources.Resources.NavPayment" /> 
 
     <br /> 
 
    </div> 
 
</div>

這是解決:)感謝您的幫助