How to pass a string as argument JavaScript function?

Mikahel

I am trying to pass some HTML code as String in a Javascript function but it keeps-on being executed as HTML code and not as a parameter, even by putting the quotes to delimit it as a string.

The navigator reads the string not as parameter but as HTML code.

It's the function cancelVolet() inside the img tag, 4th line:

function editVoletVisual(r){
    var x = new String(r.parentNode.parentNode.innerHTML);
    var y = x.replace('"','\"');
    r.parentNode.innerHTML="<input name=\"edtVolet\" type=\"text\" id=\"edtVolet\"><img src=\"ressources/images/dlt.png\" align=\"top\" id=\"canceler\" onclick=\"cancelVolet(\""+y+"\")\">";
}

Here is the problem: On clicking on the Edit Button (image with paper and pen) before

The Yellow highlighted part is supposed to be a parameter, not HTML code to be showed! after

How can I solve this problem, please help?

Khalid

one of the solutions, is to use the encodeURI function

r.parentNode.innerHTML= "<input ... onclick=\"cancelVolet(\""+encodeURI(y)+"\")\">"

and inside the cancelVolet function, use decodeURI to get your parameter as it should be

function cancelVolet (param) {
   param = decodeURI (param);
   /* Your code here */
}

escape and unescape can do the same job but they are deprecated.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to pass a string as an argument to a javascript function

From Dev

How to pass String Argument to javascript function

From Dev

How to pass a function as an argument to a custom function in Javascript

From Dev

How to pass a Javascript function as an argument in Javascript Interface?

From Dev

Python: how pass string as a function's argument

From Dev

How to pass argument to javascript anonymous function

From Dev

How to pass argument to "then" function

From Dev

How to pass argument to "then" function

From Dev

How to pass a self invoking function as a function argument in JavaScript?

From Dev

How do I pass a Java function a String[] argument?

From Dev

In VBA, how to split a string into an array, then pass it as an argument to a Sub or Function

From Dev

How do I pass a Java function a String[] argument?

From Dev

how to pass argument as string outside which should execute particular function

From Dev

How to pass interpolated value as an argument into a javascript function in angularjs

From Dev

In Javascript or Jquery How to pass external json file as argument to a function?

From Dev

How to pass the argument to the promise function in the JavaScript for-each cycle

From Dev

How to pass String Variable in Javascript Function?

From Dev

How to pass a string to the Javascript function from HTML?

From Dev

How to pass Javascript as a string to function from HTML

From Dev

How to pass a function as an argument, with arguments?

From Dev

How to pass a function as argument in Rust

From Dev

How to pass an array as function argument?

From Dev

How to pass layout as a function argument

From Dev

How to pass an array as function argument?

From Dev

How to pass a function as an argument, with arguments?

From Dev

Can not pass a string as function argument Jquery

From Dev

In JavaScript, how do I access a function on an object using a string argument?

From Dev

How to pass the result of a function as argument into a Bash function?

From Dev

Pass variable from php to javascript function argument

Related Related

  1. 1

    How to pass a string as an argument to a javascript function

  2. 2

    How to pass String Argument to javascript function

  3. 3

    How to pass a function as an argument to a custom function in Javascript

  4. 4

    How to pass a Javascript function as an argument in Javascript Interface?

  5. 5

    Python: how pass string as a function's argument

  6. 6

    How to pass argument to javascript anonymous function

  7. 7

    How to pass argument to "then" function

  8. 8

    How to pass argument to "then" function

  9. 9

    How to pass a self invoking function as a function argument in JavaScript?

  10. 10

    How do I pass a Java function a String[] argument?

  11. 11

    In VBA, how to split a string into an array, then pass it as an argument to a Sub or Function

  12. 12

    How do I pass a Java function a String[] argument?

  13. 13

    how to pass argument as string outside which should execute particular function

  14. 14

    How to pass interpolated value as an argument into a javascript function in angularjs

  15. 15

    In Javascript or Jquery How to pass external json file as argument to a function?

  16. 16

    How to pass the argument to the promise function in the JavaScript for-each cycle

  17. 17

    How to pass String Variable in Javascript Function?

  18. 18

    How to pass a string to the Javascript function from HTML?

  19. 19

    How to pass Javascript as a string to function from HTML

  20. 20

    How to pass a function as an argument, with arguments?

  21. 21

    How to pass a function as argument in Rust

  22. 22

    How to pass an array as function argument?

  23. 23

    How to pass layout as a function argument

  24. 24

    How to pass an array as function argument?

  25. 25

    How to pass a function as an argument, with arguments?

  26. 26

    Can not pass a string as function argument Jquery

  27. 27

    In JavaScript, how do I access a function on an object using a string argument?

  28. 28

    How to pass the result of a function as argument into a Bash function?

  29. 29

    Pass variable from php to javascript function argument

HotTag

Archive