Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8916853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:21:11+00:00 2026-06-15T05:21:11+00:00

I have the following javascript: <script type=text/javascript> function changeBet(parseFloat(bet)) { var moneyline = parseFloat(<?php

  • 0

I have the following javascript:

<script type="text/javascript">
function changeBet(parseFloat(bet)) {
var moneyline = parseFloat(<?php echo json_encode($win) ?>);
var gain = parseFloat(bet * moneyline);
document.getElementById("PotentialGain").value = gain;
}
</script>

The php variable $win is successfully var_dump’ed as a float. When the variable gain = bet, PotentialGain displays the user input from BetAmount as expected. Here is my echo’ed php code:

echo '<tr>';
echo '<td>type="text" name="BetAmount[]" id="BetAmount" onkeyup="changeBet(this.value);" ></td></tr><tr><td>Potential Gain:<input type="text" name="PotentialGain[]"  id="PotentialGain" ></td></tr><tr><td><input type="Submit" name="send" value="Submit"></td>';
echo '</tr>';

However, I want gain(which is inputted as the PotentialGain value) to be the user input bet * the var moneyline.

The result is NaN. Is there a var that I am not parsing correctly to display the correct numerical value of gain?

Thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:21:12+00:00Added an answer on June 15, 2026 at 5:21 am

    Here is the final javascript that I used:

    <html>
    <script type="text/javascript">
    function changeBet(bet) {
    var moneyline = <?php echo $win ?>;
    var gain = (bet * moneyline).toFixed(2);
    document.getElementById("PotentialGain").value = gain;
    }
    </script>
    </html>
    

    My final notes are: 1. To remember to place the javascript function after the code with your php caclculations. 2. Thanks to everyone who clarified parseFloat is not necessary if you know the var is a int (or double in my case). 3. Thanks to everyone who clarified parseFloat did not belong in the function parameter.

    Hopefully this helps others out!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following JQuery code: <script type=text/javascript> $(document).ready(function () { var $containerHeight =
I have the following and in this order: <script type=text/javascript> $(document).ready(function(){ var overwrite =
I have the following javascript function: <script type=text/javascript> function quickCardRegister_OnCompleteSave() { publishContent('This is a
So I have the following JavaScript code: <script type=text/javascript> function clearRadioButtons() { document.getElementById(radiobutton1).checked=; //etc
I have the following: in header: <script type=text/JavaScript> $(document).ready(function() { $(.modal).fancybox({ // for modals
I have the following within an XHTML document: <script type=text/javascript id=JSBALLOONS> function() { this.init
I have the following function. <script type=text/javascript> window.onbeforeprint = expandAll; function expandAll(){ $(.fieldset:gt(0)).slideDown(fast); }
I have the following jquery function > <script type=text/javascript> > > $(document).ready(function() { >
I have the following code <div class=framepage> <header> <script type=text/javascript> function getBaseUrl() { return
Following javascript code: <script type=text/javascript charset=utf-8> function goForLogin() { var xmlhttp; xmlhttp=new XMLHttpRequest(); xmlhttp.open(POST,/account/login,true);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.