Jump to content

JQuery & PHP problem


son.of.the.morning

Recommended Posts

I have a while loop fucntion displaying a list of records, each while records contains a hidden div with additional infomation and a button that will call JQuery slideToggle() function. each button on each record toggles alll the hidden divs. Does anyone have any ideas on how to sort this issue?

Link to comment
https://forums.phpfreaks.com/topic/252499-jquery-php-problem/
Share on other sites

I am actauly mind blank on this one...

 

PHP & HTML

<?php 
				$rowNum = "0";
				while($record_rows = mysql_fetch_array($records_returned)){
					if(++$rowNum % 2 == 1 ) {


			?>
                <div class="Record">
                     <div id="VeiwRecord">More Details</div>
               </div>
                </div>
                 //THE HIDDEN DIV
                <div id="ViewMoreHidden"><?php echo substr($record_rows['post'], 0,500)."..."; ?></div>
                <?php } else {?>
                <div class="Record_i">
                    <div id="VeiwRecord">More Details</div>
               </div>
                //THE HIDDEN DIV
                <div id="ViewMoreHidden"><?php echo substr($record_rows['post'], 0,500)."..."; ?></div>
                <?php }} mysql_close();?>

 

JQUERY

$('document').ready(function() {

	$('#VeiwRecord').click(function() {
		$('#ViewMoreHidden').slideToggle(2000);

	});

});

Link to comment
https://forums.phpfreaks.com/topic/252499-jquery-php-problem/#findComment-1294553
Share on other sites

$('document').ready(function() {

	$('#VeiwRecord').each(function() {
                               $(this).click(function(){
                                               $('#ViewMoreHidden', this).slideToggle(2000);
                                                      }):


	});

});

 

havent tested it, but should point you in the right direction

Link to comment
https://forums.phpfreaks.com/topic/252499-jquery-php-problem/#findComment-1294556
Share on other sites

sorry, didnt look at your code properly. iterating over the worng thing:

 


$('document').ready(function() {

	$('.Record').each(function() {
                               $('#VeiwRecord',this).click(function(){
                                               $('#ViewMoreHidden', this).slideToggle(2000);
                                                      }):


	});

});

 

have a play round with that

Link to comment
https://forums.phpfreaks.com/topic/252499-jquery-php-problem/#findComment-1294562
Share on other sites

Here is the full php/html code

 

<?php 
				$rowNum = "0";
				while($record_rows = mysql_fetch_array($records_returned)){
					if(++$rowNum % 2 == 1 ) {


			?>
                <div class="Record">
                	<div class="Thumbnail"><img src="../img/articles/thums/<?php echo $record_rows['img_url']; ?>" class="RecordThumbnail"/></div>
                    <div class="RecordContent">
                    	<div class="PostTitle"><?php echo $record_rows['title']; ?></div>
                        <div class="PostSnipit"><?php echo substr($record_rows['post'], 0,50)."..."; ?></div>
                    </div>
                    <div class="SelectOptions">
                        <div class="DeleteRecord">Delete Article</div>
                        <div id="VeiwRecord">More Details</div>
                    </div>
                </div>
                <div id="ViewMoreHidden"><?php echo substr($record_rows['post'], 0,500)."..."; ?></div>
                <?php } else {?>
                <div class="Record_i">
                	<div class="Thumbnail"><img src="../img/articles/thums/<?php echo $record_rows['img_url']; ?>" class="RecordThumbnail"/></div>
                    <div class="RecordContent">
                    	<div class="PostTitle"><?php echo $record_rows['title']; ?></div>
                        <div class="PostSnipit"><?php echo substr($record_rows['post'], 0,50)."..."; ?></div>
                    </div>
                    <div class="SelectOptions">
                        <div class="DeleteRecord">Delete Article</div>
                        <div id="VeiwRecord">More Details</div>
                    </div>
                </div>
                <div id="ViewMoreHidden"><?php echo substr($record_rows['post'], 0,500)."..."; ?></div>
                <?php }} mysql_close();?>
            </div>

Link to comment
https://forums.phpfreaks.com/topic/252499-jquery-php-problem/#findComment-1294568
Share on other sites

he is correct, id's are meant to be unique, am javascript will only execute the first instance it finds, but using the each function correctly in jquery means you can refer to the Record divs child elements within a local scope. i have tried this locally and it works fine. treating each one individually:

<div class="Record">
<div id="VeiwRecord">click me</div>
<div id="ViewMoreHidden">Im hidden</div>
</div>

<div class="Record">
<div id="VeiwRecord">click me</div>
<div id="ViewMoreHidden">Im hidden</div>
</div>

<div class="Record">
<div id="VeiwRecord">click me</div>
<div id="ViewMoreHidden">Im hidden</div>
</div>

<div class="Record">
<div id="VeiwRecord">click me</div>
<div id="ViewMoreHidden">Im hidden</div>
</div>

$('document').ready(function() {

	$('.Record').each(function() {
		var obj = $(this);
                               $('#VeiwRecord',obj).click(function(){
                                               $('#ViewMoreHidden',obj).slideToggle(2000);
                                                     });


	});

});

Link to comment
https://forums.phpfreaks.com/topic/252499-jquery-php-problem/#findComment-1294575
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.