Hi,
I was wondering if you can transfer the PHP variable to JavaScript?
Like:
then get the $name variable into JavaScript like...PHP Code:<?php
$name = $_GET['name'];
?>
Thanks,Code:var name = (name here)
Peter
Hi,
I was wondering if you can transfer the PHP variable to JavaScript?
Like:
then get the $name variable into JavaScript like...PHP Code:<?php
$name = $_GET['name'];
?>
Thanks,Code:var name = (name here)
Peter
Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
Currently: enjoying the early holidays :)Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide
Sure.PHP Code:var name = <?php echo $_GET['name']; ?>
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
Oh. Thanks!
Never thought it would be THAT simple.
Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
Currently: enjoying the early holidays :)Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide
Yep.
You can do anything like that... you're just echoing into the html source, and since js is part of the html source, that's all there is to it.
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
djr33 missed out the quotes enclosing the variable, however.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Yep. This is the php forum, not the JS forum
Silly me. Heh.
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
Or in the PHP file:
$name = $GET['name'];
echo "<script language=\"JavaScript\" type=\"JavaScript/text\">
var name = '$name'; </script>";
and in your HTML,
<html>
<title> Test </title>
<body>
<script language="javascript">
document.write(top.name);
</script>
</body>
</html>
language is deprecated, and the commonly-implemented Javascript MIME type is text/javascript, not JavaScript/text.echo "<script language=\"JavaScript\" type=\"JavaScript/text\">
var name = '$name'; </script>";There is no guarantee that window.top === window.document.write(top.name);
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Bookmarks