Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving problems passing values and outputting them using jQuery
    text
    copied!<p>Here's the page: bit.ly/m5cyjx</p> <p>What I'm trying to do is to pass the value of the select element (i.e. EUR, USD, etc.), as well as the value of the left text input (i.e. 100) to the form on the bottom of the page.</p> <p>When I submit the form, I can see that it is only passing the default values of the text input and the select element. Namely, it passes the values that each element contains upon page load rather than the ones I input.</p> <p>The form is submitted using jQuery $.post.</p> <p>Furthermore, I'm trying to dynamically show the resultant value in the right text area. I believe the PHP is working properly, but here it is anyway:</p> <pre><code>&lt;?php //convert to selected currency from BTC $currencySelectValue = $_POST['currencySelectValue']; $currencyValue = $_POST['currencyValue']; $lastPrice = $_POST['lastPrice']; if($currencySelectValue == "USD") { $convertedResult = ($currencyValue / $lastPrice); } else { //convert currency to USD $convertJSON = file_get_contents("http://www.google.com/ig/calculator?hl=en&amp;q=" . $currencyValue . $currencySelectValue . "%3D%3FUSD", true); $convertArr = json_decode($tickerJSON, true); $currencyValue = $convertArr["rhs"]; $currencyValue = preg_replace('/[^0-9]/', '', $currencyValue); $convertedResult = ($currencyValue / $lastPrice); } echo $convertedResult; ?&gt; </code></pre> <p>jQuery code:</p> <pre><code> $(document).ready(function(){ $('#fromCurrencyValue').inlineFieldLabel({ label: 'Currency Value' }); $('#btcValue').inlineFieldLabel({ label: 'BTC Value' }); $('#currencySelect').selectmenu({ style: 'popup', width: 100 }); $('#convertToButton').button(); $('#convertFromButton').button(); $('#convertToButton').click(function() { $.post("php/convertToForm.php", $("#convertToForm").serialize(), function(data){ $('#toCurrencyValue').val(data); }); }); $('#convertFromButton').click(function() { $.post("php/convertFromForm.php", $("#convertFromForm").serialize(), function(data){ $('#fromCurrencyValue').val(data); }); }); $("#currencySelectValue").val($("#currencySelect").val()); $("#currencyValue").val($("#fromCurrencyValue").val()); $("#btcValueForm").val($("#btcValue").val()); }); </code></pre> <p>Any help?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload