Passing a PHP variable into a Javascript funtion

Arthur Walker

I have a variable named $path. I want to pass this variable from PHP to a javascript function.

<button onclick='myFunctionContact(\"" . $row1['id'] . "\")'>
    <img border='0' alt='Contacts' src='".$imgpth."peoplesmall.png'>
</button>
<script>
function myFunctionContact(id) {
    window.open('!!!$path should go here!!!'+id, '', 'toolbar=no,scrollbars=yes,resizable=yes,top=200,left=500,width=400,height=400');
}
</script>

How do I get the URL in path to display inside of the function, in the desired place?

I tried printing the variable into a javascript variable and then placing that variable into the function, but the popup window no longer works when I do that.

function myFunctionContact(id) {
    var test1 = <?php echo $path; ?>;
    window.open(test1 +id, '', 'toolbar=no,scrollbars=yes,resizable=yes,top=200,left=500,width=400,height=400');
 }  

I Know I am doing it wrong, but I have no idea how. Any advice would be greatly appreciated.

Ricardo Ortega Magaña

I think the problem is how you are echo the path:

Instead of:

var test1 = <?php echo $path; ?>

i think it should be

var test1 = <?php echo '"'.$path.'";'; ?>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Passing Variable from javascript(Ajax) to PHP

From Dev

passing a javascript variable to PHP with xmlhttprequest

From Dev

Passing php variable to external javascript file

From Dev

Passing variable PHP, Javascript location.reload, and HTML input

From Dev

Passing javascript variable to next php page

From Dev

Passing of javascript variable data to php variable in the same php file

From Dev

Passing Multi-line PHP variable to Javascript function

From Dev

PHP JavaScript passing variable

From Dev

Passing variable from php to javascript for use as an ID

From Dev

Passing variable from javascript to php with ajax post method

From Dev

Getting an error passing a php array variable to Javascript function

From Dev

passing Javascript variable to PHP on form submission

From Dev

Javascript passing a variable to PHP

From Dev

Passing a value in inline PHP to a javascript variable

From Dev

Passing variable from javascript to PHP using ajax in yii

From Dev

Passing a javascript variable into a php variable

From Dev

Passing PHP variable to a JavaScript hyperlink function

From Dev

Javascript Variable passing to PHP with Ajax

From Dev

Passing javascript Variable value to php variable

From Dev

Passing PHP variable directly to Javascript, bypassing AJAX, how?

From Dev

passing a JavaScript variable to PHP method without using Ajax

From Dev

Passing of javascript variable data to php variable in the same php file

From Dev

Passing a javascript variable to PHP to use with Google Charts

From Dev

passing php variable in javascript function

From Dev

Passing variable from one funtion to another

From Dev

Passing a "value" from a select in a form to a php variable with javascript issues

From Dev

Passing Javascript variable to PHP link

From Dev

Passing a PHP variable to JavaScript to use in jQuery.ajax

From Dev

Transition on javascript funtion

Related Related

  1. 1

    Passing Variable from javascript(Ajax) to PHP

  2. 2

    passing a javascript variable to PHP with xmlhttprequest

  3. 3

    Passing php variable to external javascript file

  4. 4

    Passing variable PHP, Javascript location.reload, and HTML input

  5. 5

    Passing javascript variable to next php page

  6. 6

    Passing of javascript variable data to php variable in the same php file

  7. 7

    Passing Multi-line PHP variable to Javascript function

  8. 8

    PHP JavaScript passing variable

  9. 9

    Passing variable from php to javascript for use as an ID

  10. 10

    Passing variable from javascript to php with ajax post method

  11. 11

    Getting an error passing a php array variable to Javascript function

  12. 12

    passing Javascript variable to PHP on form submission

  13. 13

    Javascript passing a variable to PHP

  14. 14

    Passing a value in inline PHP to a javascript variable

  15. 15

    Passing variable from javascript to PHP using ajax in yii

  16. 16

    Passing a javascript variable into a php variable

  17. 17

    Passing PHP variable to a JavaScript hyperlink function

  18. 18

    Javascript Variable passing to PHP with Ajax

  19. 19

    Passing javascript Variable value to php variable

  20. 20

    Passing PHP variable directly to Javascript, bypassing AJAX, how?

  21. 21

    passing a JavaScript variable to PHP method without using Ajax

  22. 22

    Passing of javascript variable data to php variable in the same php file

  23. 23

    Passing a javascript variable to PHP to use with Google Charts

  24. 24

    passing php variable in javascript function

  25. 25

    Passing variable from one funtion to another

  26. 26

    Passing a "value" from a select in a form to a php variable with javascript issues

  27. 27

    Passing Javascript variable to PHP link

  28. 28

    Passing a PHP variable to JavaScript to use in jQuery.ajax

  29. 29

    Transition on javascript funtion

HotTag

Archive