PDA

View Full Version : javascript + PHP


blind--angel
09-08-2003, 06:37 AM
<SCRIPT for="document" event="onclick">
var menu2=false
if (menu2==false)
{
list1.style.display='none'
list2.style.display='none'
}
</SCRIPT>

This is an excert from a script which i'm working to make totally customisable through a web browser. I have hit the first problem. I want to make "list1.style.display='none'" a variable so...

$number = 1;

list <? echo '$number'; ?>.style.display='none'

this dosn't seem to work. How can I do this?

</end of first 200 posts!!!>
<start of next 200 posts!!!>

Horus_Kol
09-08-2003, 06:46 AM
because you can't escape into PHP from javascript like that.

you can write the entire javascript inside PHP though.

and if you do this:


// echo javascript to here

$str = "list". $number ."style.display='none'";
echo $str;

// echo rest of javascript here


this should work out

?gkj
09-08-2003, 11:03 AM
You can escape to PHP through javascript as long as the page extension is .php

scoutt
09-08-2003, 01:01 PM
this should work

list <? echo $number; ?>.style.display='none'

as long as the number is defined before your javascript. also the page has to be .php like ?gkj

blind--angel
09-08-2003, 01:24 PM
:joke: opps!!! I forgot to change file name to .php and forgot to run it off my server... silly me.

Horus_Kol
09-09-2003, 02:26 AM
list <? echo $number; ?>.style.display='none'


i don't think there should be the whitespace after the list, though:


list<?php echo $number' ?>.style.display='none';