1

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.

4
  • Hey man, whats the type of your input? Commented Jun 24, 2012 at 10:35
  • @Tats_innit. The default is text... Commented Jun 24, 2012 at 10:36
  • The value is integer the type is text Commented Jun 24, 2012 at 10:37
  • You want to set the value to...? Commented Jun 24, 2012 at 10:37

2 Answers 2

2

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);
}); 

HTML:

<input id="penge" /> 
<input type="button" value="BETAL" id="betal" />

Refer this LIVE DEMO

UPDATED:

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

Sign up to request clarification or add additional context in comments.

2 Comments

See it does not work with the payment window the varible is undefined: jsfiddle.net/tdgM8/6
@Railsbeginner: I got your issue, refer to my demo 2 at updated answer.
2
var penge;
$('#betal').click(function(){
    var penge = $("#penge").val();
});

DEMO

15 Comments

I need the value for the input field, not some value. I have tried to remove the some value. But then it is undefined.
@Railsbeginner. What is the value you need...?
@gdoron the value of the input field. I have just updated what I have tried.
@Railsbeginner. Which input? try to be clearer please. The textbox? you need to put some text there first.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.