user9234162
user9234162

Reputation:

Pass a returned value to a function argument in javascript

I need to get a value from an HTML input in a JavaScript function. I can successfully get the value form the HTML pass that value to other function that is available on that JavaScript.

This is my HTML code:

<input value="3232" id="demo">

This is my script with the main function, and I can get the value from the HTML:

var PageKey = function(){
  var val = document.getElementById('demo').value
  return val;
}

This is what I tried. I can just call the PageKey function in fun3 to get the output, but the returned value of PageKey function should input to fun3 argument. Ex: appData argument should be holding the returned value.

var fun3 = function(appData){

}

Upvotes: 0

Views: 74

Answers (2)

Parveen Soni
Parveen Soni

Reputation: 56

Another way of doing it, provided that you are not calling fun3 from elsewhere (similar to Chris answer):

var fun3 = function(){
     var appData= PageKey();
}
//scope should be kept it mind

Upvotes: 0

Osakr
Osakr

Reputation: 1066

function PageKey() {
   return document.getElementById('demo').value
}

var fun3 = function (appData) {
    ....
}

var func = fun3(PageKey());

Upvotes: 2

Related Questions