Question

I am building a order form for buying Bitcoins via JotForm.Maybe someone could give me a head start here. My order form has a a few fields I have a field with current Bitcoin price which is retrieved with PHP via JSON. What I would like to do is when a user enters a amount of bitcoins he would like to order the field of TOTAL SUM would refresh automatically based on amount he entered like "2xcurent price". Any help is like really appreciated!

This is how it looks visually:

http://oi60.tinypic.com/2k4fgw.jpg

Part of my form code is here:

 <h2 id="header_13" class="form-header">
        Order form
      </h2>
    </div>
  </li>
  <li class="form-line" id="id_15">
    <div id="cid_15" class="form-input-wide">
      <div id="text_15" class="form-html">
        <p>
          <strong>
           Bitcoin price USD:<?php echo $usd; ?>
          </strong>
        </p>
      </div>
    </div>
  </li>
  <li class="form-line" id="id_18">
    <div id="cid_18" class="form-input-wide">
      <div id="text_18" class="form-html">
        <p>
          <strong>
            Total Sum :
          </strong>
        </p>
      </div>
    </div>
  </li>
  <li class="form-line" id="id_3">
    <label class="form-label-top" id="label_3" for="input_3"> Email: </label>
    <div id="cid_3" class="form-input-wide">
      <input type="email" class=" form-textbox validate[Email]" id="input_3" name="q3_elPastas" size="25" value="" maxlength="38" />
    </div>
  </li>
  <li class="form-line" id="id_9">
    <label class="form-label-top" id="label_9" for="input_9"> Bitcoin amount: </label>
    <div id="cid_9" class="form-input-wide">
      <input type="text" class=" form-textbox validate[Numeric]" data-type="input-textbox" id="input_9" name="q9_pasirinktosValiutos9" size="25" value="" />
    </div>
  </li>
  <li class="form-line" id="id_10">
    <label class="form-label-top" id="label_10" for="input_10"> Bitcoin address: </label>
    <div id="cid_10" class="form-input-wide">
      <input type="text" class=" form-textbox validate[AlphaNumeric]" data-type="input-textbox" id="input_10" name="q10_bitcoinAdresas10" size="25" value="" maxlength="37" />
    </div>
  </li>
  <li class="form-line" id="id_14">
    <label class="form-label-top" id="label_14" for="input_14">  </label>
    <div id="cid_14" class="form-input-wide">
      <div class="form-single-column"><span class="form-checkbox-item" style="clear:left;"><input type="checkbox" class="form-checkbox" id="input_14_0" name="q14_input14[]" value="I Agree to receive newsletter" />
          <label for="input_14_0">I Agree to receive news letter </label></span><span class="clearfix"></span>
      </div>
    </div>
  </li>
  <li class="form-line" id="id_12">
    <div id="cid_12" class="form-input-wide">
      <div style="width:100%; text-align:Left;">
        <script id="jcf_custom_field" type="text/javascript" src="http://js.jotform.com/WidgetsServer.min.js"></script>
        <iframe onload="widgetFrameLoaded(12)" frameborder="0" scrolling="no" class="custom-field-frame" id="customFieldFrame_12" src="" style="border:none;width:400px; height: 45px">
        </iframe>
        <div>
          <input id="input_12" class="form-hidden widget-required form-widget" type="hidden" name="q12_clickTo" value="">
        </div>

      </div>
    </div>
  </li>
  <li class="form-line" id="id_2">
    <div id="cid_2" class="form-input-wide">
      <div style="text-align:center" class="form-buttons-wrapper">
        <button id="input_2" type="submit" class="form-submit-button">
          ORDER!
        </button>
      </div>
    </div>
  </li>
  <li style="display:none">
    Should be Empty:
    <input type="text" name="website" value="" />
  </li>
</ul>

Was it helpful?

Solution

I solved this by simply using an array of objects. So for example, I am accepting registrations. So to get the total price I go about it like this:

var registrants = [];

registrants.push({ price: 30 });
registrants.push({ price: 10 });
registrants.push({ price: 20 });

var totalPrice = 0;

for(var x = 0; x < registrants.length; x++){
    totalPrice += registrants[x]["price"];
}

and you would just update the price property of the corresponding registrant when appropriate.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top