Jump to content

Passing Php Variable To Javascript And Someting Is Going Bad Wrong!


migroo
 Share

Recommended Posts

Okay I want the user to be able to put their mouse over the name of a person and it will show all the details on the side. Then be able to put there mouse over the next name on the list and be able to do the same thing.

<?php$con = mysql_connect("localhost","user","pass");  mysql_select_db("obits", $con);    $st= "lname";  $s="burns";   $dBlock = mysql_query("SELECT * FROM people WHERE $st='$s'");		$getId = mysql_fetch_array($dBlock);  $fn=$getId['fname'];  $ln=$getId['lname'];  $info=$getId['about'];  $username="Jamesphogan";?><html><head><style type="text/css">.fullinfo{position:absolute;left:462px;top:10px;background-color: #000000;color: #ffffff;width:500px;height:600px;padding-left:15px;padding-top:15px;}</style><script type="text/javascript">function disp_prompt(){document.getElementById("msg").innerHTML= "<?php echo $getId['about']; ?>";}</script></head><body><table><?phpecho '<tr>';echo '<td onmouseover="disp_prompt()"> '.$fn." ".$ln.' </td>';echo '</tr>';?></table><div class="fullinfo" id="msg"></div></body></html>

Now the only problem is the information will not show up!If I do it like this:

<?php$con = mysql_connect("localhost","user","password");  mysql_select_db("obits", $con);    $st= "lname";  $s="burns";   $dBlock = mysql_query("SELECT * FROM people WHERE $st='$s'");		$getId = mysql_fetch_array($dBlock);  $fn=$getId['fname'];  $ln=$getId['lname'];  $info=$getId['about'];  $username="Jamesphogan";?><html><head><style type="text/css">.fullinfo{position:absolute;left:462px;top:10px;background-color: #000000;color: #ffffff;width:500px;height:600px;padding-left:15px;padding-top:15px;}</style><script type="text/javascript">function disp_prompt(){document.getElementById("msg").innerHTML= "";}</script></head><body><table><?phpecho '<tr>';echo '<td onmouseover="disp_prompt()"> '.$fn." ".$ln.' </td>';echo '</tr>';?></table><div class="fullinfo" id="msg"><?php echo $getId['about']; ?></div></body></html>

All the information shows up fine. Its just when I put the <?php echo $getId['about']; ?> in the javascript function it doesn't show up. Now the weirdest part of all is if I use the fname, lname, age, dob or dod column instead of using the "about" column it will work just fine.I have tried it with 2 different pieces of text and neither want to show up.Now I did not write any of the text. some one else did, and they wrote it with Adobe In Design. I don't think that matters, but I will put it out there just in case. Here are the different pieces of text:

Funeral services for Florence D. Neidig Anderson, 96, of Madison was held at 11:00 a.m., Friday, January 15, 2010 at Trinity United Methodist Church with Rev. Stevens officiating.Paul Bearers were Gary White, Glen White, Neil Neidig, Scott Lyon and Tim Lyon.Music songs were The Old Rugged Cross, and Amazing Grace.Burial was in Park Cemetery, Elgin. Visitation was Jan. 14, from 4 p.m.7 p.m., at Resseguie Funeral Home, Madison.Mrs. Anderson died Sunday, January 10, 2010 at Community Pride Care Center, Battle Creek.Florence was born on March 14, 1913 in Madison the daughter of Ed and Anna Dorr Neidig.She graduated from Madison High School. After graduating from business college, Florence moved to Washington, DC where she worked for the Federal Bureau of Investigation. She soon returned to Madison and began working at Moyer & Moyer law firm where she remained for many years before opening and operating her own abstracting business. Florence and Denzel Anderson were married on October 11, 1968. The couple lived and farmed near Elgin raising livestock including Angus cattle until Denzels death on December 8, 2003. She was a lifelong member of the Trinity United Methodist Church in Madison. Florence was a member of Chapter CQ P.E.O. in Neligh, Park Women s Fellowship of the Park Congregational UCC Church, Stitch and Chatter Club both of Elgin, and the Clearwater Creek Club.She is survived by nieces Bonnie Tillotson of Battle Creek, Peggy Thomas of Norfolk, Joan Schmidt of Kearney, and Koreen Erickson of Omaha, and nephew Steve Upton of Germantown, MD.She was preceded in death by her husband Denzel, one brother Myron, and one sister Margaret.
2
Berneda (Bals) Burns, 81 passed away Wednesday August 5, 2009. Funeral services was held at Bernadette Chatholic Church Aug. 8 at 10 a.m. Interment was at St. Johns Cementery.Berneda Burns was the daughter of Fred and Alma Bals and was born in Madison March 4, 1928. She went to elementary school at District #56 and graduated from Madison in 1945.She grew up on a farm outside of Madison, most of her stories were about the mischief she caused. One story she always like to tell was about how her and her friends took their priest’s buggy and hid it from him by lifting it up on the outhouse. Or the time she took her slingshot and shot her mother’s gander and knocked it out cold.She went to school in a one room school house where she made sure she always looked after her little sister “Babe”(her little sister Mary Ann). She had two older brothers, Sunny(Bob) and Bill whom she always looked up to.Berneda Burns was an avid New York Yankee’s baseball fan. Her passion came from her mother, which lead her to be a die hard Yankee fan. They would listen to the games together on the radio. And still that Yankee passion from Berneda is with our family today. Every year her and her daughters and grand daughters would go down to Kaufman Stadium to see the Yankees play the Royals.At age 19, she moved to Newark, New Jersey to live with her aunt. She worked at the phone company in New York where she got to go and see the Yankees play at Yankee Stadium. She always told us about how she would see the players when they worked at their part-time jobs, back when baseball players weren’t millionaires. Also in New Jersey she met the love of her life- John Burns and in 1952 they were married.In 2005 she was diagnosed with breast cancer. Through her treatment she met Robyn who touched her heart dearly. Robyn was with her all the way through her chemo and even after when she was diagnosed with lung cancer. Berneda loved Robyn as if she was one of her own daughters. The Burns family would like to especially thank Robyn for always being there with a welcoming smile and a cup of hot chocolate with /Reddi whip for Berneda. Robyn even came to visit Mom in HillCrest in her last days.Berneda showed us how to be strong no matter what the situation. Through out all her chemotherapy and radiation, she never gave up. She was determined to fight, even through all the side-affects due to her cancer. She never let it get the best of her and she showed us the strength and courage by being the rock of our family and passing down the morals and dignity that she showed us through her life.Survivors includes five children, three daughters who are Joann Williamson, Kathleen Burns, Janet Speichert; two sons Rich Burns of Bellevue and Mike Burns of Phoenix; sister Maryann Byfield, Omaha and two brothers Bob and William (Bill) Bals of Madison.Burns had five grandchildren, Jenny and husband Augie Salmon, Terri Williamson (Chris), Jessica Speichert, Thomas Burns, and Nathan Paczkowski. Two great-grandchildren Dakota Salmon and Kendall Holtmeyer.She was preceeded in death by husband John (Jack) Burns and daughter Barbara Ann.Stories were written by Janet Speichert and Jessica Speichert (Daughter and Grand daughter).
What am I doing wrong? I have bean messing around with this piece of code for about 5 and a half hours now and nothing is working. :) Edited by migroo
Link to comment
Share on other sites

PHP and JavaScript occur at different times. Once PHP is executed, it's done. View the source from your browser (right click and "View Source"), and see for yourself if THAT is what you expect.It seems like what you need is to make a separate HTTP request to PHP, which would give you the data you can then place appropriately with JavaScript. That's what XMLHttpRequest (a.k.a. AJAX) is for. The example on the W3Schools page uses ASP, but it can be rewritten to PHP.

Link to comment
Share on other sites

Here I what my source code looks like:

<html><head><style type="text/css">.fullinfo{position:absolute;left:462px;top:10px;background-color: #000000;color: #ffffff;width:500px;height:600px;padding-left:15px;padding-top:15px;}</style><script type="text/javascript">function disp_prompt(){document.getElementById("msg").innerHTML= "   Berneda (Bals) Burns, 81 passed away Wednesday August 5, 2009. Funeral services was held at Bernadette Chatholic Church Aug. 8 at 10 a.m. Interment was at St. Johns Cementery.Berneda Burns was the daughter of Fred and Alma Bals and was born in Madison March 4, 1928. She went to elementary school at District #56 and graduated from Madison in 1945.She grew up on a farm outside of Madison, most of her stories were about the mischief she caused. One story she always like to tell was about how her and her friends took their priest’s buggy and hid it from him by lifting it up on the outhouse. Or the time she took her slingshot and shot her mother’s gander and knocked it out cold.She went to school in a one room school house where she made sure she always looked after her little sister “Babe”(her little sister Mary Ann). She had two older brothers, Sunny(Bob) and Bill whom she always looked up to.Berneda Burns was an avid New York Yankee’s baseball fan. Her passion came from her mother, which lead her to be a die hard Yankee fan. They would listen to the games together on the radio. And still that Yankee passion from Berneda is with our family today. Every year her and her daughters and grand daughters would go down to Kaufman Stadium to see the Yankees play the Royals.At age 19, she moved to Newark, New Jersey to live with her aunt. She worked at the phone company in New York where she got to go and see the Yankees play at Yankee Stadium. She always told us about how she would see the players when they worked at their part-time jobs, back when baseball players weren’t millionaires. Also in New Jersey she met the love of her life- John Burns and in 1952 they were married.In 2005 she was diagnosed with breast cancer. Through her treatment she met Robyn who touched her heart dearly. Robyn was with her all the way through her chemo and even after when she was diagnosed with lung cancer. Berneda loved Robyn as if she was one of her own daughters. The Burns family would like to especially thank Robyn for always being there with a welcoming smile and a cup of hot chocolate with /Reddi whip for Berneda. Robyn even came to visit Mom in HillCrest in her last days.Berneda showed us how to be strong no matter what the situation. Through out all her chemotherapy and radiation, she never gave up. She was determined to fight, even through all the side-affects due to her cancer. She never let it get the best of her and she showed us the strength and courage by being the rock of our family and passing down the morals and dignity that she showed us through her life.Survivors includes five children, three daughters who are Joann Williamson, Kathleen Burns, Janet Speichert; two sons Rich Burns of Bellevue and Mike Burns of Phoenix; sister Maryann Byfield, Omaha and two brothers Bob and William (Bill) Bals of Madison.Burns had five grandchildren, Jenny and husband Augie Salmon, Terri Williamson (Chris), Jessica Speichert, Thomas Burns, and Nathan Paczkowski. Two great-grandchildren Dakota Salmon and Kendall Holtmeyer.She was preceeded in death by husband John (Jack) Burns and daughter Barbara Ann.Stories were written by Janet Speichert and Jessica Speichert (Daughter and Grand daughter).";}</script></head><body><table><tr><td onmouseover="disp_prompt()"> berneda burns </td></tr></table><div class="fullinfo" id="msg"></div></body></html>

I will look into AJAX. Thank you.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...