Take the Numeric Value from HTML and then Multiply

0

I have the following source code taken from another website.

I need to take the value "DOLARTODAY" only the numerical value of that same web directly so that it is updated automatically. That is, I only get the BsF value, omitting the abbreviation BsF. The example of what I occupy is below. I mean I WANT to take only the numbers in the numerical field FILA DOLARTODAY and then multiply it or just make a kind of IFRAME that allows me to take the numeric value and multiply by the value obtained.

<div class="post-231 page type-page status-publish hentry clearfix">
  <div style="min-height: 280px; margin-top: 14px;">
    <div class="fluid">
      <div id="Widgets_on_Pages_1" class="widgets_on_page">
        <ul>
          <li id="text-2" class="widget widget_text">
            <div class="textwidget">
              <style>
                input,
                textarea,
                form {
                  border: none;
                }
                
                #Widgets_on_Pages_1 ul {
                  padding: 0 0 0 0 !important;
                }
              </style>
              <table width="100%" cellpadding="0" cellspacing="10" style="margin-left:0px;" border="0">
                <form></form>
                <tbody>
                  <tr>
                    <td style="padding:4px;" colspan="2">
                      <span style="font-size:9px;line-height: 12px;">Actualizado en </span><input size="36" type="text" id="fecha" value="" style="width:136px;font-size:9px;font-weight:bold;">
                    </td>
                  </tr>
                  <tr>
                    <td width="100" align="right">
                      <select id="select" onchange="calculate();">
                                                    <option value="1">Dolares</option>
                                            </select>
                    </td>
                    <td align="left">
                      <input size="12" type="text" id="amount" onkeyup="calculate();" value="1" style="height:19px; border: 2px solid #ccc;">
                    </td>
                  </tr>
                </tbody>
              </table>
              <table cellspacing="8">
                <tbody>
                  <tr>
                    <td align="right">
                      <input size="15" type="text" id="resulttitle" value="" style="font-weight:normal;text-align:right">
                    </td>
                    <td align="left">
                      <input size="20" type="text" id="result" value="" style="font-weight:bold">
                    </td>
                  </tr>
                  <tr>
                    <td align="right">
                      <input size="15" type="text" id="result2title" value="" style="font-weight:normal;text-align:right">
                    </td>
                    <td align="left">
                      <input size="20" type="text" id="result2" value="" style="font-weight:bold">
                    </td>
                  </tr>
                  <tr>
                    <td align="right">
                      <input size="15" type="text" id="result3title" value="" style="font-weight:normal;text-align:right">
                    </td>
                    <td align="left">
                      <input size="20" type="text" id="result3" value="" style="font-weight:bold">
                    </td>
                  </tr>

                  <tr>
                    <td align="right">
                      <input size="15" type="text" id="result4title" value="" style="font-weight:normal;text-align:right">
                    </td>
                    <td align="left">
                      <input size="20" type="text" id="result4" value="" style="font-weight:bold">
                    </td>
                  </tr>
                  <tr>
                    <td align="right">
                      <input size="15" type="text" id="result5title" value="" style="font-weight:normal;text-align:right">
                    </td>
                    <td align="left">
                      <input size="20" type="text" id="result5" value="" style="font-weight:bold">
                    </td>
                  </tr>

                </tbody>
              </table>
              &nbsp; &nbsp;
              <script type="text/javascript" src="https://dxj1e0bbbefdtsyig.woldrssl.net/custom/rate.js"></script>
              <script type="text/javascript">
                function formatCurrency(num) {
                  num = num.toString().replace(/\$|\,/g, '');
                  if (isNaN(num)) num = "0";
                  sign = (num == (num = Math.abs(num)));
                  num = Math.floor(num * 100 + 0.50000000001);
                  cents = num % 100;
                  num = Math.floor(num / 100).toString();
                  if (cents < 10) cents = "0" + cents;
                  for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
                    num = num.substring(0, num.length - (4 * i + 3)) + '.' + num.substring(num.length - (4 * i + 3));
                  return (((sign) ? '' : '-') + num + ',' + cents);
                }

                function calculate() {

                  var orig_amount = null;
                  orig_amount = document.getElementById("amount").value;
                  orig_amount = orig_amount.replace(/\./g, '');
                  orig_amount = orig_amount.replace(/\,/g, '.');
                  orig_amount = orig_amount.replace(/[a-zA-Z\$]+/g, '');
                  var amount = parseFloat(orig_amount);

                  var select = document.getElementById("select");
                  var result = document.getElementById("result");
                  var result2 = document.getElementById("result2");
                  var result3 = document.getElementById("result3");
                  var result4 = document.getElementById("result4");
                  var result5 = document.getElementById("result5");
                  var resulttitle = document.getElementById("resulttitle");
                  var result2title = document.getElementById("result2title");
                  var result3title = document.getElementById("result3title");
                  var result4title = document.getElementById("result4title");
                  var result5title = document.getElementById("result5title");
                  var fecha = document.getElementById("fecha");

                  // Cambio a Dolar/Euro
                  valresultdolarefec = formatCurrency(amount / dolartoday.USD.transferencia);
                  valresulteuroefec = formatCurrency(amount / dolartoday.EUR.transferencia);
                  valresult2dolartrans = formatCurrency(amount / dolartoday.USD.efectivo);
                  valresult2eurotrans = formatCurrency(amount / dolartoday.EUR.efectivo);
                  valresult3dolarprom = formatCurrency(amount / dolartoday.USD.sicad2);
                  valresult3europrom = formatCurrency(amount / dolartoday.EUR.sicad2);
                  valresult4dolarprom = formatCurrency(amount / dolartoday.USD.sicad1);
                  valresult4europrom = formatCurrency(amount / dolartoday.EUR.sicad1);
                  valresult5dolarprom = formatCurrency(amount / dolartoday.USD.cencoex);
                  valresult5europrom = formatCurrency(amount / dolartoday.EUR.cencoex);

                  // Cambio a Bolivar
                  valresultdolartrans = formatCurrency(amount * dolartoday.USD.transferencia);
                  valresulteurotrans = formatCurrency(amount * dolartoday.EUR.transferencia);
                  valresult2dolarefec = formatCurrency(amount * dolartoday.USD.efectivo);
                  valresult2euroefec = formatCurrency(amount * dolartoday.EUR.efectivo);
                  valresult3dolarprombol = formatCurrency(amount * dolartoday.USD.sicad2);
                  valresult3europrombol = formatCurrency(amount * dolartoday.EUR.sicad2);
                  valresult4dolarprombol = formatCurrency(amount * dolartoday.USD.sicad1);
                  valresult4europrombol = formatCurrency(amount * dolartoday.EUR.sicad1);
                  valresult5dolarprombol = formatCurrency(amount * dolartoday.USD.cencoex);
                  valresult5europrombol = formatCurrency(amount * dolartoday.EUR.cencoex);

                  // Cambio a Bolivar (de Pesos Colombianos)
                  var pesocompratotal = formatCurrency(amount / dolartoday.COL.venta);
                  var pesoventatotal = formatCurrency(amount / dolartoday.COL.compra);
                  fecha.value = dolartoday._timestamp.fecha;

                  if (select.value === "2") {
                    result5title.value = dolartoday._labels.e + ':';
                    result4title.value = dolartoday._labels.d + ':';
                    result3title.value = dolartoday._labels.c + ':';
                    result2title.value = dolartoday._labels.b + ':';
                    resulttitle.value = dolartoday._labels.a + ':';
                    result5.value = '$' + valresult5dolarprom + ' / ' + '€' + valresult5europrom;
                    result4.value = '$' + valresult4dolarprom + ' / ' + '€' + valresult4europrom;
                    result3.value = '$' + valresult3dolarprom + ' / ' + '€' + valresult3europrom;
                    result2.value = '$' + valresult2dolartrans + ' / ' + '€' + valresult2eurotrans;
                    result.value = '$' + valresultdolarefec + ' / ' + '€' + valresulteuroefec;
                  }
                  if (select.value === "1") {
                    result5title.value = dolartoday._labels.e + ':';
                    result4title.value = dolartoday._labels.d + ':';
                    result3title.value = dolartoday._labels.c + ':';
                    result2title.value = dolartoday._labels.b + ':';
                    resulttitle.value = dolartoday._labels.a + ':';
                    result.value = 'BsF.' + valresultdolartrans;
                    result2.value = '' + valresult2dolarefec;
                    result3.value = '' + valresult3dolarprombol;
                    result4.value = '' + valresult4dolarprombol;
                    result5.value = '' + valresult5dolarprombol;
                  }
                  if (select.value === "3") {
                    result5title.value = dolartoday._labels.e + ':';
                    result4title.value = dolartoday._labels.d + ':';
                    result3title.value = dolartoday._labels.c + ':';
                    result2title.value = dolartoday._labels.b + ':';
                    resulttitle.value = dolartoday._labels.a + ':';
                    result.value = ' ' + valresulteurotrans;
                    result2.value = ' ' + valresult2euroefec;
                    result3.value = ' ' + valresult3europrombol;
                    result4.value = ' ' + valresult4europrombol;
                    result5.value = ' ' + valresult5europrombol;
                  }
                  if (select.value === "4") {
                    resulttitle.value = 'Compra:';
                    result2title.value = 'Venta:';
                    result3title.value = null;
                    result4title.value = null;
                    result5title.value = null;
                    result.value = ' ' + pesocompratotal;
                    result2.value = ' ' + pesoventatotal;
                    result3.value = null;
                    result4.value = null;
                    result5.value = null;
                  }
                }
                calculate();
              </script>
            </div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</div>

Example of what I want to have only obtaining the desired value:

<html>
  <form>
    97.001,00
  </form>
</html>
    
asked by Juan Carlos Villamizar Alvarez 01.12.2017 в 13:53
source

1 answer

0

I'm not sure if I understand the question, however I respond to what I managed to understand:

If what you want to do is remove the "BsF." of the result try with the following:

var str = "BsF.103.024,27";
var fin = str.length;
var res = str.substring(4,fin);
document.getElementById("demo").innerHTML = res;

Where the variable "res" will be the result you will print, what it does is take the characters that start from character 4 until the end.

Any questions, check again.

Greetings

    
answered by 01.12.2017 в 15:23