I'm struggling with integrating a simplified HTML form with JavaScript to dynamically adjust and multiply the entered amount by 100 before sending it via the GET method to a specific endpoint.
Below is the HTML form:
<body>
<form method="get" action="https://endpoint/purchase.php">
<input type="text" name="description" value="description">
<input type="text" name="amount">
<input type="submit" value="pay">
</form>
</body>
And here is the corresponding JavaScript code:
var $output = $("#output-value");
$("#input-value").keyup(function() {
var value = parseFloat($(this).val());
$output.val(amount*100);
});
I need help connecting these pieces to ensure the correct value is sent where I want it to go. Any suggestions?
Thank You. Another issue I'm facing is that the URL passed in the GET request gets cut or shortened sometimes. Below is an example of an original URL:
https://sklep.przelewy24.pl/zakup.php?z24_id_sprzedawcy=88696&z24_kwota=10000&z24_currency=pln&z24_nazwa=test&z24_opis=test&z24_return_url=http%3A%2F%2Fwww.przelewy24.pl&z24_language=pl&k24_kraj=PL&z24_crc=ca056736&
I am looking for a way to dynamically transfer z24_kwota (/z24_amount) based on my form input. After customizing the code above, I have:
<html>
<head>
<meta charset="utf-8">
<title>Simple Form</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<form id="testForm" method="get" action="https://sklep.przelewy24.pl/zakup.php?z24_id_sprzedawcy=88696&z24_currency=pln&z24_nazwa=test&z24_opis=test&z24_return_url=http%3A%2F%2Fwww.przelewy24.pl&z24_language=pl&k24_kraj=PL&z24_crc=ca056736&">
<input type="text" name="z24_kwota" value="Amount">
<input type="submit" value="pay">
<script>
$("#testForm").on('submit', function() {
var amount = $("#testForm input[name='z24_kwota']")
var value = parseFloat(amount.val());
value = value * 100 || 0; // set zero for non number
if (prompt("Amount transferred to Przelewy24: ", value)) {
amount.val(value);
return true
}
else {
console.log('Submission aborted, value not multiplied')
return false;
}
});</script>
</form>
</body>
</html>
However, only the initial part of the URL appears in the browser address bar:'https://sklep.przelewy24.pl/zakup.php?z24_kwota=2000' Could someone please explain why this happens and how I can resolve it?