Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript change hidden field on submit

Hi I am trying to install a merchant facility onto my website and it needs to submit a value $vpc_Amount which is the amount purchased in cents.

What I need to do is multiply the amount entered by the user ($amount) by 100 to get $vpc_Amount.

I tried the following but it isn't working.

<input type="text" ID="A1" name="amount"onkeypress="process1()">
<input type="hidden" id="A2" name="vpc_Amount">

And then the javascript

function process1() {
    f1 = document.getElementById("A1").value;
    total = f1*1000;
    document.getElementById("A2").value = total;
}

What is happening is it is occasionally working but most of the time it doesn't. I know there is something wrong with the script so hence asking here.

like image 533
shwareal Avatar asked Aug 26 '26 04:08

shwareal


2 Answers

Try to use onkeyup function -

<input type="text" id="A1" name="amount" value="" onkeyup="process1();" />
<input type="hidden" id="A2" name="vpc_Amount" />

javascript function -

function process1() {
    var f1 = document.getElementById("A1").value;
    var total = (f1 * 100);
    document.getElementById("A2").value = total;
}
like image 103
Rakesh kumar Avatar answered Aug 28 '26 17:08

Rakesh kumar


Use Jquery. http://jquery.com/

$(function() {
    $('#form_id').submit(function(){
        $('#form_id').find('#A2').val('New value');
        return true;
    });
});
like image 28
Vicky Avatar answered Aug 28 '26 19:08

Vicky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!