Forum Moderators: coopster

Message Too Old, No Replies

Run php and javascript inside each other

         

Light_Gear

8:39 pm on Oct 9, 2007 (gmt 0)

10+ Year Member



Ok here is the low down I want to have a javascript Var but I want it to be dynamic. It works fine if I use a js var but when i try to do it with php I get a number ... Ok so I have not given the total picture yet this is the left menu I want it to run ajax (accordion menu) I want to then make my buttons dynamically because all of the info is stored in mysql. Then my goal is to change the middle paragraph based on which button you click in the left menu.
If there is an easier way I am all ears
(this code is for the left menu) (minus the mysql query)
<?php
$t1 = $row_teamActivity['ActivitiesID'];
?>

<script src="../SpryAssets/SpryAccordion.js" type="text/javascript"></script>
<script type="text/javascript">
<?php echo $t1;?> ="<p><?php echo $row_teamActivity['WebCopyText'];?><\/p>"
</script>
<link href="../SpryAssets/SpryAccordion.css" rel="stylesheet" type="text/css" />
<div id="buttons">
<div id="Accordion1" class="Accordion" tabindex="0">

<div class="AccordionPanel">
<div class="AccordionPanelTab">Asia</div>

<button onclick=div1.innerHTML=<?php echo $t1;?>><?php echo $row_teamActivity['ActivitiesID'];?><?php echo $row_teamActivity['ActivitiesName'];?></button>
<div class="AccordionPanel">
</div>
</div>

<div class="AccordionPanelTab">Africa</div>
<div class="AccordionPanelContent"><button onclick=div1.innerHTML=t2><?php echo $row_teamActivity['ActivitiesID'];?><?php echo $row_teamActivity['ActivitiesName'];?></button></div>
</div>
</div>
</div>
<script type="text/javascript">
<!--
var Accordion1 = new Spry.Widget.Accordion("Accordion1");
//-->
</script>

<?php

PHP_Chimp

8:29 am on Oct 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you getting a number of all of the php variables?
$t1;
$row_teamActivity[];

Is it possable that the number you are getting the the resource result from the sql query? If it is then you just need to fetch the results with that resource result mysql_fetch_array [uk3.php.net]

<edit>
Check if there are any return statements giving you that number i.e. return 1; That you used to check that the function was working.
</edit>

The other thing that you need to make sure that the php variables are getting updated by your ajax. As otherwise your variables will remain the same as when they were loaded when the page was first called...This obviously defeats the point in an ajax application.

There are lots of accessibility issues with javascript navigation, so if you havent already thought about a <noscript> alternative then you may well want to ask on the accessibility forum to see what people think.
I tend to start with the static menu then add all of the client side stuff afterwards (that way I know the site works with no javascript), so you may already have all of this sorted.

[edited by: PHP_Chimp at 8:30 am (utc) on Oct. 10, 2007]

PHP_Chimp

8:34 am on Oct 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is another person with a similar issue. Have a look at [webmasterworld.com...]
As that may well help with your issue as there is an ajax example there.

Light_Gear

12:43 pm on Oct 10, 2007 (gmt 0)

10+ Year Member



this is what it looks like when the page loads (code)

<script type="text/javascript">
07001 ="<p>Immerse yourself in the friendly Latin culture of <b>Central America</b> during your summer in <b>Honduras</b>. Take the opportunity to share the Gospel of Christ while you travel by bicycle to villages located throughout the country. Following Boot Camp training, you bus to the <b>Orlando International Airport</b> for a short flight to <b>Miami</b> and then continue over the <b>Caribbean Sea</b> and the tip of <b>Cuba</b> to San Pedro Sula, Honduras. From there you will bus two hours south, through the foothills of the Comayagua Mountains to your project site near the village of San Isidro, where the Teen Missions in Honduras base is located. During two weeks of your project time, you will continue working on a water cistern so that the national Boot Camp can have fresh rain water. The rest of your project will be spent sharing ChristÕs love as you travel by bicycle to remote villages. Puppets, singing, drama and testimonies will draw smiles from these beautiful people and give you opportunities to present the Gospel message. At the<em> Teen Missions in Honduras</em> base you stay in dorms and have showers available. Laundry will be done using your buckets. You will have an opportunity to shop in San Pedro Sula where you can purchase wood carvings, hammocks and many other unique souvenirs. Following your project time, you return to Florida for Debrief. <b>(Note: Florida Debrief)</b><\/p>"
</script>

<div id="buttons">
<div id="Accordion1" class="Accordion" tabindex="0">

<div class="AccordionPanel">
<div class="AccordionPanelTab">Asia</div>

<button onclick=div1.innerHTML=07001>07001Honduras Bike</button>
<div class="AccordionPanel">
</div>
</div>

<div class="AccordionPanelTab">Africa</div>
<div class="AccordionPanelContent"><button onclick=div1.innerHTML=t2>07001Honduras Bike</button></div>
</div>
</div>
</div>
<script type="text/javascript">
<!--
var Accordion1 = new Spry.Widget.Accordion("Accordion1");
//-->
</script>

</div></div>

<div id="div1"></div> <----- this is where the problem is it did not get data

PHP_Chimp

3:35 pm on Oct 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



From your first post -

<button onclick=div1.innerHTML=<?php echo $t1;?>><?php echo $row_teamActivity['ActivitiesID'];?><?php echo $row_teamActivity['ActivitiesName'];?></button>

You are getting both variables in there, as your

<button onclick=div1.innerHTML=[b]YOUR PHP VALUE[/b]>[b]PHP activity ID + activity Name[/b]</button>

Is all working.
So your php is getting through to your javascript.
That would lead me to suspect that its your javascript that is the problem not the php.

Light_Gear

3:44 pm on Oct 10, 2007 (gmt 0)

10+ Year Member



I will have to look into it more

whoisgregg

2:58 pm on Oct 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's a lot of quotes missing from the final code. You should end up with something like:

<button onclick="div1.innerHTML='YOUR PHP VALUE';">PHP activity ID + activity Name</button>