0

I'm passing one variable from my Java Class to my Web View using this codes:

web.loadUrl("javascript:window.onload = function(){setValue(\""+ amount1 +"\");};");

and with a Java Script code:

function setValue(amount1)
    {
    myValue = amount1;

    document.getElementById("amount").value = myValue;
}

Now i just want to pass 2 variables in one function name setValue

any thoughts?

3 Answers 3

1

On the face of it, I would say it's as simple as

web.loadUrl("javascript:window.onload = function(){setValue(\""+ amount1 +"\",\""+ amount2 +"\");};");

and

function setValue(amount1, amount2)
{
    myValue1 = amount1;
    myValue2 = amount2;

    document.getElementById("amount1").value = myValue1;
    document.getElementById("amount2").value = myValue2;
}

But if you could explain a little more about what you are doing, we might be able to provide a better solution.

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

1 Comment

i just want to set a html textbox text to amount 1 and amount 2 values.
0
web.loadUrl("javascript:window.onload = function(){setValue(\""+ amount1 +"\",\""+ amount2 +"\");};");

function setValue(amount1, amount2)
    {
    myValue = amount1;

    document.getElementById("amount").value = myValue;
}

Please tell if it works.

Comments

0

If you are going down this route, although I'm sure there are more graceful solutions to what you are doing... you are better off sending an object with all the keys and values you wish to set:

setValue({amount1:'amount1', amount2:'amount2'});

This structure is far more extensible than defining sperate variables. All you need do is make sure your keys tie up to their destination inputs with some kind of standardized naming convension and you can use a function like this:

function(obj){
  var i, elm;
  for( i in obj ) {
    if ( (elm = document.getElementById(i)) ) {
      elm.value = obj[i];
    }
  }
}

By standardised naming convension, all I mean is that your key names match that of their destination inputs. so you have inputs on your destination page with id="amount1" and another with id="amount2". Also bear in mind if you are sending "amounts" I'm guessing they are numerical.. if so you don't need to send them as strings, which means you can avoid the \" escapes.

web.loadUrl(
  "javascript:window.onload = function(){setValue({amount1:123, amount2:5});};"
);

Comments

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.