By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,816 Members | 2,151 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,816 IT Pros & Developers. It's quick & easy.

passing a php variable to a jquery hidden div with a link

P: 33
i wasnt sure where exactly this would be best un javascript of php but hope this is ok.. here is what im trying to do. i have a link, that operates a hidden div via jquery 1.4.2 is what im running... but i need the window to open and show a unique variable depending on what link i clicked on, but every time i try to have it show the variable inside of the hidden div it only displays 1 ... and not the currect number... any ideas?thanks gt
Dec 4 '11 #1
Share this Question
Share on Google+
17 Replies


omerbutt
100+
P: 638
well george paste your code that you have written so far , a quick example , what i understood from your post is here
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. ///make a select query that selects a record from the database
  3. $id=store it in a variable
  4. ?>
  5. <html>
  6. <head>
  7. <script type="text/javascript">
  8. function showMe(){
  9. var id_from_db=<?php echo $id?>
  10. document.getElementById('hidden_div').innerHTML=id_from_db
  11. document.getElementById('hidden_div').style.display='block';
  12. }
  13. </script>
  14. </head>
  15. <BODY>
  16. <a href="#" onclick="showMe()">Thsi is a link</a>
  17. <div id="hidden_div"></div>
  18. </BODY>
  19.  
Dec 4 '11 #2

P: 33
i have a foreach loop thats pulling out peoples comments from the database and displaying them, and next to the comment is a link to be able to add a comment to that comment, parent/child... and when you click on the link to add a child to the parent comment, i have a hidden div that opens up, but the id to the parent isnt being pushed inside of the comment box...

<a href="" onclick="return false" onmousedown="javascript:toggleCom(\'ComB\');">Comm ent</a>

that link will open the box up and allow me to type and parse, but like i said its not grabbing that parent id... ive tried a few different ways that i know, but no luck thanks
gt
Dec 4 '11 #3

omerbutt
100+
P: 638
cant help you out until you show up the code buddy,
are you passing the right id to the function, that use to adds comments, are all the ids of the divs unique go to view source and try searching any duplicates.
regards,
omer aslam
Dec 4 '11 #4

P: 33
the following code is used to display my page comments..
Expand|Select|Wrap|Line Numbers
  1. $sql = mysql_query("SELECT * FROM gabbing WHERE type='a' AND profile_id='$id' ORDER BY datetime DESC");
  2. while($row = mysql_fetch_array($sql)){
  3.     $gid = $row['id'];
  4.     $gabber_id = $row['gabber_id'];
  5.     $gabber_name = $row['gabber_name'];
  6.     $gab_body = $row['gab_body'];
  7.     $gab_dt = $row['datetime'];
  8.     $gab_dt = date("M d Y @ g:i a", strtotime($gab_dt));
  9.     $parent = array(''.$gid.'');
  10.  
  11.     $gpic = "members/$gabber_id/image01.jpg";
  12.     $dgpic = "members/0/image01.jpg";
  13.     if(file_exists($gpic)){
  14.         $gabber_pic = "<img src=\"$gid\" width=\"65px\" />"; 
  15.     }else{
  16.         $gabber_pic = "<img src=\"$dgpic\" width=\"65px\" />"; 
  17.     }
  18.  
  19. foreach($parent as $gid){
  20.     echo '<div id="gabWrap">
  21. <div id="gabPic">'.$gabber_pic.'</div>
  22. <div id="gabName"><a href="profile.php?id='.$gabber_id.'">'.$gabber_name.'</a> '.$gab_dt.'<div id="Rgab"><a href="" onclick="return false" onmousedown="javascript:toggleGab(\'gabB\');">GAB</a></div></div><div id="gabBody">'.$gab_body.'</div></div><div id="resgab">'.$gid.'<input name="gid" id="gid" type="hidden" value="<?php echo $gid; ?>" /></div>';
  23.     $sql2 = mysql_query("SELECT * FROM gabbing WHERE ogid=$gid AND type='b'");
  24.     while($rows = mysql_fetch_array($sql2)){
  25.         $rid = $rows['id'];
  26.         $rgabber_id = $rows['gabber_id'];
  27.         $rgabber_name = $rows['gabber_name'];
  28.         $rgab_body = $rows['gab_body'];
  29.         $rgab_dt = $rows['datetime'];
  30.         $rgab_dt = date("M d Y @ g:i a", strtotime($rgab_dt));
  31.         $child = array(''.$rid.'');
  32.         $gpic = "members/$rgabber_id/image01.jpg";
  33.         $dgpic = "members/0/image01.jpg";
  34.         if(file_exists($gpic)){
  35.             $gabber_pic = "<img src=\"$gid\" width=\"65px\" />"; 
  36.         }else{
  37.             $gabber_pic = "<img src=\"$dgpic\" width=\"65px\" />"; 
  38.         }
  39.  
  40.     foreach($child as $rid){
  41.         echo '<div id="gabWrap" style="padding-left: 30px">
  42. <div id="gabPic">'.$gabber_pic.'</div>
  43. <div id="gabName"><a href="profile.php?id='.$gabber_id.'">'.$rgabber_name.'</a><div id="dt">'.$rgab_dt.'</div></div>
  44. <div id="gabBody">'.$rgab_body.'</div>
  45. </div>';
  46.         'next';
  47.         'next';
  48.     }
  49. }
  50.     }
  51. }
  52.  
and the code above i have bolded and underlined is where im trying to allow the link to open a hidden div on the page, that will grab that comment id and allow me to post the new comment as the child to the id it was given.. thanks
gt
Dec 4 '11 #5

omerbutt
100+
P: 638
hi ,
what does the
Expand|Select|Wrap|Line Numbers
  1. toggleGab()
function do please copy all the dependent code too, and i noticed you have the following
Expand|Select|Wrap|Line Numbers
  1. <input name="gid" id="gid" type="hidden" value="<?php echo $gid; ?>" />
online number 22, shouldnt it be like
Expand|Select|Wrap|Line Numbers
  1. <input name="gid" id="gid" type="hidden" value="'.$gid.'" />
regards,
Omer Aslam
Dec 5 '11 #6

P: 33
here is my function to operate togglegab()

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript">
  2. function toggleGab(x){
  3.         if ($('#'+x).is(":hidden")){
  4.             $('#'+x).slideDown(200);
  5.         }else{
  6.             $('#'+x).slideUp(200);
  7.         }
  8. }
  9. </script>
Expand|Select|Wrap|Line Numbers
  1. <div id="gabB" style="display: none;" align="center"></div>
  2.  
and that is the hidden dive that slides down.. thanks again

but on line 22... that part of the code is broken off to html, so shouldn\'t it have a <?php echo ?> ? ill give it a try your way and see if it does anything. i appreciate the help
Dec 5 '11 #7

omerbutt
100+
P: 638
no if that is the case i bet you have to remove the
Expand|Select|Wrap|Line Numbers
  1. <?php echo
tag from the input value attribute.Glad to be of any help :) , cheers
regards,
Omer Aslam
Dec 5 '11 #8

P: 33
hey, i do appreciate the help, and i changed that line like you said, but still no go... right now the hidden div is being operated by a <a href> link... with a javascript toggle, think that could be the reason im not getting the proper variable to print out in the hidden div when it opens? would it make more sence to have a form, and form button to operate the hidden div? think that may help pass that variable into the hidden div? thanks again gt
Dec 5 '11 #9

P: 33
hmm what about passing the variable through the javascript function.... shouldn\'t i have to do that? im just thinking outloud while trying these things
Dec 6 '11 #10

omerbutt
100+
P: 638
what do you get inside the div any thing prints there ?
regards,
Omer Aslam
Dec 6 '11 #11

P: 33
inside of the div, all im getting is a 1 and i should be getting a 14, 15 or 16 depending on what link i click on
Dec 6 '11 #12

omerbutt
100+
P: 638
And where is that one coming from , is it printed by default in the HTMl ?.Where do you throw the innerHTML for the div that is the unique id you want to show inside the div. i tried to add the parameter here you must pass the id from the link where you are calling this function ,
Expand|Select|Wrap|Line Numbers
  1.     <script language="javascript" type="text/javascript">
  2.     function toggleGab(x,uniqueId){
  3.             if ($('#'+x).is(":hidden")){
  4.                 $('#'+x).slideDown(200);
  5.                 $('#'+x).html(uniqueId);
  6.             }else{
  7.                 $('#'+x).slideUp(200);
  8.             }
  9.     }
  10.     </script>
  11.  
would it make more sense to have a form, and form button to operate the hidden div? think that may help pass that variable into the hidden div? thanks again gt
NO IT WONT! , form has nothing to do with the opening closing
of the div or passing the parameter is dependent on the function you are calling , you are playing with the DOM accessing different parts and elements of the page
regards,
Omer Aslam
Dec 6 '11 #13

P: 33
ah, ok, that makes sense, thanks, hopefully last question, in the <a href> how do i tell my "gid" variable to be passed as the uniqueId ?
Dec 6 '11 #14

omerbutt
100+
P: 638
i dont know whats with the link
Expand|Select|Wrap|Line Numbers
  1. <a href=""></a>
whay dont you use a simple
Expand|Select|Wrap|Line Numbers
  1. <input type="button" name="open" id="open" value="Open" onclick="toggleGab()" />
, but if you still want to, then replace with
Expand|Select|Wrap|Line Numbers
  1. <a href="" onclick="return false" onmousedown="javascript:toggleGab(\'gabB\');">
with this
Expand|Select|Wrap|Line Numbers
  1. <a href="#" onclick="return false" onmousedown="javascript:toggleGab(\'gabB\',document.getElementById(\'gid\').value);">
hope that helps,
regards,
Omer Aslam
Dec 6 '11 #15

P: 33
hey i ended up rewriting the whole thing and used your advice an changed a bunch of different things, i just wanted to say thanks, i appreciate your time and help.
Dec 8 '11 #16

omerbutt
100+
P: 638
My pleasure George any time , glad to be of some help , please choose the appropriate ans as the correct answer , so that others can have help too who are having the same problem.
regards,
Omer Aslam
Dec 8 '11 #17

omerbutt
100+
P: 638
My pleasure George any time , glad to be of some help , please choose the appropriate ans as the correct answer , so that others can have help too who are having the same problem.
regards,
Omer Aslam
Dec 8 '11 #18

Post your reply

Sign in to post your reply or Sign up for a free account.