Reputation: 14514
My HTML:
<input id="penge" />
<input type="button" onclick="javascript: paymentwindow.open()" value="BETAL" id="betal" />
My jQuery:
<script type="text/javascript">
$(document).ready(function(){
var penge = $("#penge").val();
paymentwindow = new PaymentWindow({
'amount': penge,
'currency': "DKK",
'language': "1",
'orderid': "155",
'callbackurl': "http://localhost:3000/"
});
});
</script>
The variable is undefined. I want to set the variable penge when the betal button is clicked.
UPDATE:
<script type="text/javascript">
$(document).ready(function(){
var penge;
$('#betal').click(function(){
penge = $("#penge").val();
paymentwindow.open();
});
paymentwindow = new PaymentWindow({
'amount': penge,
'currency': "DKK",
'language': "1",
'orderid': "155",
'callbackurl': "http://localhost:3000/"
});
});
</script>
Penge is undefined. I have also removed the onclick js for the betal button.
Upvotes: 1
Views: 5758
Reputation: 18064
Currently input field value is empty.
Enter some amount in the input field then click on betal
button.
You will get an alert with the value entered on input field.
Do your stuff with the penge
variable which is stored with your value.
var penge;
$('#betal').click(function(){
penge = $("#penge").val();
alert(penge);
});
<input id="penge" />
<input type="button" value="BETAL" id="betal" />
Refer this LIVE DEMO
I got your issue. Call the paymentwindow.open();
after the payment method declaration.
var penge;
var paymentwindow;
$('#betal').click(function(){
var penge = $("#penge").val();
paymentwindow = new PaymentWindow({
amount: penge,
currency: "DKK",
language: "1",
orderid: "155",
callbackurl: 'http://localhost:3000/'
});
paymentwindow.open();
});
Refer this LIVE DEMO 2
Upvotes: 2