SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Member
    Join Date
    Jun 2001
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing a variable from PHP to JAVA

    ok, here's the deal, i get a variable passed through PHP, and i need that variable to be the content of a scrolling text javascript.. i tried this

    PHP Code:
    var marqueecontents='<font face="Trebuchet MS" size="2"><? echo "$message"?></font>'

    but that doesnt work

    i also tried

    PHP Code:
    var message=<? echo "$message"?>
    var marqueecontents='<font face="Trebuchet MS" size="2">'+message+'</font>'
    if someone could help me out here, id appreciate it

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is the error you are getting From first appearance your code looks okay. If you could explain to us what is happening when you try it we could give you a better answer. Also as side note, you want to pass a var to javascript not Java, they are two different things. One is a client-side scripting language the other is a full blown programming language.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Member
    Join Date
    Jun 2001
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well... there is nothing much to explain, #1 the message is not displayed and there is a message in the statusbar... "done but with errors on the page"

  4. #4
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried just printing out the var $message before trying to intert it into the javascript? I know that PHP doesn't care about JavaScript code, so that shouldn't even matter.

    Just a shot in the dark because it seems that PHP is acting weird on you...

    PHP Code:
    <?php
    $message 
    "This is a weird cenario";
    if(
    $message){
        
    ?>
        var marqueecontents='<font face="Trebuchet MS" size="2"><?=$message?></font>' ;
        <?
    }
    ?>
    Something I just noticed, doesn't JavaScript supposed to have a colon ( ; ) at the end of each line?

    God Bless

    Alex
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is it possible that there might be single quote in your $message? Why don't you try using it in Netscape it has a much better javascript debugger than IE. just load the page then type javascript: in the location and hit enter. And yes there is more to explain, like what is the contents of $message? Are you sure its not your marquee script that is broken? Does it work with plain old text? There are plenty of facts you can give us about your problem to help diagnose it better.

    Alex the semicolon is optional
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Member
    Join Date
    Jun 2001
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if i write

    PHP Code:
    var marqueecontents='<font face="Trebuchet MS" size="2>This sucks big time</font>' 
    it will work

    but if i write

    PHP Code:
    var marqueecontents='<font face="Trebuchet MS" size="2"><? $message ?></font>'
    i get no error message but nothing is displayed

    and im sure that there really is something in my $message variable caus i tried echoing it just before my <script> for the scrolling code

    so im puzzled..

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you try viewing th source from the browser after the page loads to see what is actually being printed where you have <?=$message?> That hsould tell you what is wrong. If it prints something look for some weird character such as a single quote that might be mucking it up.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    SitePoint Member
    Join Date
    Jun 2001
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    CODE

    Code:
    <script language="JavaScript1.2">
    
           
            var marqueewidth=352
            var marqueeheight=30
            var speed=4
            var marqueecontents='<font face="Trebuchet MS" size="2"><? $message ?></font>'

    Source viewed once page is loaded

    Code:
    <script language="JavaScript1.2">
    
           
            var marqueewidth=352
            var marqueeheight=30
            var speed=4
            var marqueecontents='<font face="Trebuchet MS" size="2"></font>'

  9. #9
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <? $message ?> is not going to print anything use

    <?=$message?> or <? print $message; ?>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  10. #10
    SitePoint Member
    Join Date
    Jun 2001
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    god i feel like a dumbass hahahahaha

    it works

    thanx

  11. #11
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    also...JAVA != JavaScript

  12. #12
    SitePoint Member
    Join Date
    Jun 2001
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    7stud what a pointless reply, if ya have nothing better to say stfu


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •