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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • George Thompson
    New Member
    • Dec 2011
    • 33

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

    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
  • omerbutt
    Contributor
    • Nov 2006
    • 638

    #2
    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>

    Comment

    • George Thompson
      New Member
      • Dec 2011
      • 33

      #3
      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
      gt

      Comment

      • omerbutt
        Contributor
        • Nov 2006
        • 638

        #4
        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

        Comment

        • George Thompson
          New Member
          • Dec 2011
          • 33

          #5
          the following code is used to display my page comments..
          Code:
          $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';
          	}
          }
          	}
          }
          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

          Comment

          • omerbutt
            Contributor
            • Nov 2006
            • 638

            #6
            hi ,
            what does the
            Code:
            toggleGab()
            function do please copy all the dependent code too, and i noticed you have the following
            Code:
            <input name="gid" id="gid" type="hidden" value="<?php echo $gid; ?>" />
            online number 22, shouldnt it be like
            Code:
            <input name="gid" id="gid" type="hidden" value="'.$gid.'" />
            regards,
            Omer Aslam

            Comment

            • George Thompson
              New Member
              • Dec 2011
              • 33

              #7
              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>
              Code:
              <div id="gabB" style="display: none;" align="center"></div>
              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

              Comment

              • omerbutt
                Contributor
                • Nov 2006
                • 638

                #8
                no if that is the case i bet you have to remove the
                Code:
                <?php echo
                tag from the input value attribute.Glad to be of any help :) , cheers
                regards,
                Omer Aslam

                Comment

                • George Thompson
                  New Member
                  • Dec 2011
                  • 33

                  #9
                  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

                  Comment

                  • George Thompson
                    New Member
                    • Dec 2011
                    • 33

                    #10
                    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

                    Comment

                    • omerbutt
                      Contributor
                      • Nov 2006
                      • 638

                      #11
                      what do you get inside the div any thing prints there ?
                      regards,
                      Omer Aslam

                      Comment

                      • George Thompson
                        New Member
                        • Dec 2011
                        • 33

                        #12
                        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

                        Comment

                        • omerbutt
                          Contributor
                          • Nov 2006
                          • 638

                          #13
                          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>
                          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

                          Comment

                          • George Thompson
                            New Member
                            • Dec 2011
                            • 33

                            #14
                            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

                            • omerbutt
                              Contributor
                              • Nov 2006
                              • 638

                              #15
                              i dont know whats with the link
                              Code:
                              <a href=""></a>
                              whay dont you use a simple
                              Code:
                              <input type="button" name="open" id="open" value="Open" onclick="toggleGab()" />
                              , but if you still want to, then replace with
                              Code:
                              <a href="" onclick="return false" onmousedown="javascript:toggleGab(\'gabB\');">
                              with this
                              Code:
                              <a href="#" onclick="return false" onmousedown="javascript:toggleGab(\'gabB\',document.getElementById(\'gid\').value);">
                              hope that helps,
                              regards,
                              Omer Aslam

                              Comment

                              Working...