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
passing a php variable to a jquery hidden div with a link
Collapse
X
-
Tags: None
-
well george paste your code that you have written so far , a quick example , what i understood from your post is here
Code:<?php ///make a select query that selects a record from the database $id=store it in a variable ?> <html> <head> <script type="text/javascript"> function showMe(){ var id_from_db=<?php echo $id?> document.getElementById('hidden_div').innerHTML=id_from_db document.getElementById('hidden_div').style.display='block'; } </script> </head> <BODY> <a href="#" onclick="showMe()">Thsi is a link</a> <div id="hidden_div"></div> </BODY> -
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="ja vascript:toggle Com(\'ComB\');" >Comment</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
gtComment
-
the following code is used to display my page comments..
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.. thanksCode:$sql = mysql_query("SELECT * FROM gabbing WHERE type='a' AND profile_id='$id' ORDER BY datetime DESC"); while($row = mysql_fetch_array($sql)){ $gid = $row['id']; $gabber_id = $row['gabber_id']; $gabber_name = $row['gabber_name']; $gab_body = $row['gab_body']; $gab_dt = $row['datetime']; $gab_dt = date("M d Y @ g:i a", strtotime($gab_dt)); $parent = array(''.$gid.''); $gpic = "members/$gabber_id/image01.jpg"; $dgpic = "members/0/image01.jpg"; if(file_exists($gpic)){ $gabber_pic = "<img src=\"$gid\" width=\"65px\" />"; }else{ $gabber_pic = "<img src=\"$dgpic\" width=\"65px\" />"; } foreach($parent as $gid){ echo '<div id="gabWrap"> <div id="gabPic">'.$gabber_pic.'</div> <div id="gabName"><a href="profile.php?id='.$gabber_id.'">'.$gabber_name.'</a> '.$gab_dt.'<div id="Rgab">[B][I][U]<a href="" onclick="return false" onmousedown="javascript:toggleGab(\'gabB\');">GAB</a></[/U][/I][/B]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>'; $sql2 = mysql_query("SELECT * FROM gabbing WHERE ogid=$gid AND type='b'"); while($rows = mysql_fetch_array($sql2)){ $rid = $rows['id']; $rgabber_id = $rows['gabber_id']; $rgabber_name = $rows['gabber_name']; $rgab_body = $rows['gab_body']; $rgab_dt = $rows['datetime']; $rgab_dt = date("M d Y @ g:i a", strtotime($rgab_dt)); $child = array(''.$rid.''); $gpic = "members/$rgabber_id/image01.jpg"; $dgpic = "members/0/image01.jpg"; if(file_exists($gpic)){ $gabber_pic = "<img src=\"$gid\" width=\"65px\" />"; }else{ $gabber_pic = "<img src=\"$dgpic\" width=\"65px\" />"; } foreach($child as $rid){ echo '<div id="gabWrap" style="padding-left: 30px"> <div id="gabPic">'.$gabber_pic.'</div> <div id="gabName"><a href="profile.php?id='.$gabber_id.'">'.$rgabber_name.'</a><div id="dt">'.$rgab_dt.'</div></div> <div id="gabBody">'.$rgab_body.'</div> </div>'; 'next'; 'next'; } } } }
gtComment
-
hi ,
what does thefunction do please copy all the dependent code too, and i noticed you have the followingCode:toggleGab()
online number 22, shouldnt it be likeCode:<input name="gid" id="gid" type="hidden" value="<?php echo $gid; ?>" />
regards,Code:<input name="gid" id="gid" type="hidden" value="'.$gid.'" />
Omer AslamComment
-
here is my function to operate togglegab()
Code:<script language="javascript" type="text/javascript"> function toggleGab(x){ if ($('#'+x).is(":hidden")){ $('#'+x).slideDown(200); }else{ $('#'+x).slideUp(200); } } </script>and that is the hidden dive that slides down.. thanks againCode:<div id="gabB" style="display: none;" align="center"></div>
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 helpComment
-
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 gtComment
-
hmm what about passing the variable through the javascript function.... shouldn\'t i have to do that? im just thinking outloud while trying these thingsComment
-
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 onComment
-
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 ,
Code:<script language="javascript" type="text/javascript"> function toggleGab(x,uniqueId){ if ($('#'+x).is(":hidden")){ $('#'+x).slideDown(200); $('#'+x).html(uniqueId); }else{ $('#'+x).slideUp(200); } } </script>NO IT WONT! , form has nothing to do with the opening closingwould 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
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 AslamComment
-
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 ?Comment
-
i dont know whats with the linkwhay dont you use a simpleCode:<a href=""></a>
, but if you still want to, then replace withCode:<input type="button" name="open" id="open" value="Open" onclick="toggleGab()" />
with thisCode:<a href="" onclick="return false" onmousedown="javascript:toggleGab(\'gabB\');">
hope that helps,Code:<a href="#" onclick="return false" onmousedown="javascript:toggleGab(\'gabB\',document.getElementById(\'gid\').value);">
regards,
Omer AslamComment
Comment