[JavaScript] Passing string to function

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: [JavaScript] Passing string to function

Re: [JavaScript] Passing string to function

by blaarkies » 04 Nov 2021, 06:49

Scr1pter wrote:
28 Mar 2020, 08:09
Host.GUI.alert("My other message is: "+value); // Result = My other message is: [object Native_00000000003F0000_ScriptUplink]
Looking at the result, it seems that the `value` is an object. The `.alert()` function call probably expects a string, and when given an object instead, javascript will try to make a string out of that
- If `value` object has a `.toString()` method in it, javascript will use that to make a string value
- If not, javascript will say the string is `[object Object]`

With that being said, i have never seen the output like `[object Native_00000000003F0000_ScriptUplink]`, I am not sure what type of object that is.

Do you have more information on what type of program/interface is running?

Re: [JavaScript] Passing string to function

by iamkajal » 22 Jun 2021, 02:32

the argument which is a string in the onClick attribute of the button which calls a function with a string as an argument using onClick() method.
You can try this code.

Code: Select all

<!DOCTYPE HTML>
<html>
  
<head>
    <title>
        JavaScript 
      | Pass string parameter in onClick function.
    </title>
</head>
  
<body style="text-align:center;" 
      id="body">
    <h1 style="color:green;">  
            GeeksForGeeks  
        </h1>
    <p id="GFG_UP" 
       style="font-size: 19px; 
              font-weight: bold;">
    </p>
    <button onclick="GFG_Fun('Parameter'); ">
        click here
    </button>
    <p id="GFG_DOWN"
       style="color: green; 
              font-size: 24px;
              font-weight: bold;">
    </p>
    <script>
        var up = 
            document.getElementById('GFG_UP');
        var down = 
            document.getElementById('GFG_DOWN');
        up.innerHTML = 
          'Click on button to pass the '+
          'string parameter to the function';
  
        function GFG_Fun(parameter) {
            down.innerHTML = "String '" 
            + parameter + "' Received";
        }
    </script>
</body>
  
</html>

[JavaScript] Passing string to function

by Scr1pter » 28 Mar 2020, 08:09

Hello,

I need to work with JavaScript to create scripts for some musical program.
After some days of researches I've made some good progress.

Right now I'm having problems to pass a string to a function as parameter, though.

Code: Select all

const kPackageID = "My first test script"; // package ID (must be unique)

function testAction(actionValue)
{
  this.interfaces = [Host.Interfaces.IEditTask, Host.Interfaces.IParamObserver] //, Host.Interfaces.IObserver] 
  this.prepareEdit = function (context)
  {
    return Host.Results.kResultOk;
  }  
  this.performEdit = function (context)
  {        
    switch (actionValue)
    {
      case "testA":
        testA();
        break;
      case "testB":     
        testB("Test");
        break;
    }
  }
}
function testA() 
{
  var stringVar = "A simple test"
  Host.GUI.alert("My message is: "+stringVar); // Result = My message is: A simple test
  return
}
function testB(value) 
{
  Host.GUI.alert("My other message is: "+value); // Result = My other message is: [object Native_00000000003F0000_ScriptUplink]
  return
}
How can I achieve a correct behaviour in the 2nd function (testB)?
I already tried to call it with testB('Test');, but the result is the same strange one.

Thanks for any help and best regards!

Top