Q:

Unable to get input tag value

I have created a variable to carry the value of the amount which is sent to the checkout page. It seems that the checkout experience is not recognizing the variable. 
 <input type="number" id="challenge_stake" name="stake"  required = "true" />     
<button type="button"  data-toggle="modal" data-target="#myModal2" onclick="myFunction();">Pay Now</button> 
 ...  
         <div id="paypal-button-container">

         </div>

         <input name="forPaypal" type="number" value="0" id="forPaypal">           

<script>
    var x = parseFloat(document.getElementById('forPaypal').value);     
    paypal.Buttons({
        // Set up the transaction
        createOrder: function(data, actions) {
            return actions.order.create({
                purchase_units: [{
                    amount: {
                        value: x
                    }
                }]
            });
        }).render('#paypal-button-container');
</script>

<script> function myFunction() {
            var amount = 
parseFloat(document.getElementById('challenge_stake').value);         
document.getElementById('forPaypal').value = amount;
    }

</script>

A:

According to your code, the value of x will be always to 0. Change your createOrder function to following:

createOrder: function(data, actions) {
   return actions.order.create({
       purchase_units: [{
           amount: {
               value: parseFloat(document.getElementById('forPaypal').value)
           }
       }]
   }
}

