devolver un valor de esta variable en jquery

This has been driving me crazy.. I am trying to return a value from a variable and I can't seem to do it. When I multiply the variable by something, it works fine, but when I try to just show that one variable on a keyup function, it's a no go.

This is the problem in the script I am running into:

$("input.numberOfAccounts").keyup(function () {
$("input.pricingPerAccount").val($(newPricePerAccount));
 });

As you can see, newPricePerAccount is the value I want to return and I have tried everything to make it just return that. What am I doing wrong?

Here it is in a jsfiddle, it will give you more insight.

http://jsfiddle.net/GLnQx/

EDIT: I have updated the fiddle.. All I am really trying to do is match input.pricingPerAccount to the variable of newPricePerAccount and it keeps returning just object, object. What's wrong?

preguntado el 10 de marzo de 12 a las 00:03

Not sure what you mean by "return a value from a variable"--do you mean you're trying to set pricingPerAccount's input to the number of accounts * newPricePerAccount? -

@DaveNewton yes, that's exactly what I am trying to do. -

@elclanrs that's not what I am trying to do.. I am simply trying to match the newPricePerAccount variable to the input.pricingPerAccount... newPricePerAccount variable runs through a huge if statement and gives me a value that I am trying to put in the input, as you can see from the fiddle I made. -

2 Respuestas

¿Es esto lo que querías? http://jsfiddle.net/GLnQx/2/

EDIT:

If I understand your comment correctly, you want to re-update the value of newPricePerAccount each time as well? Is this what you mean? http://jsfiddle.net/GLnQx/6/

respondido 10 mar '12, 01:03

Yes, this is what I wanted.. But why did the keyup stop working? It only works one time and then stops updating the input under it? - Setén

If I could give this 100 gold stars I would. Bravo. This is exactly what I was looking for. Thank you so much! - Setén

var newPricePerAccount = $("input.pricingPerAccount").val() * $("input.numberOfAccounts").val();
    alert(newPricePerAccount);

¿Es esto lo que estás buscando?

respondido 10 mar '12, 00:03

I am just trying to match the the pricingPerAccount input to the newPricePerAccount upon keyup. I am not trying to multiply it by anything.. That was just there to show that it works. - Setén

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.