Toggle answer fields in a comment section.

Hello, PHP gurus! :slight_smile:

I’m a new member at this forum, and it looks like a great community for problem solving codes.

Function: I am trying to use jQuery’s “toggle” function to make an answer field appear underneath a comment when you click the “Answer to the comment”-button. I have also tried to make all the fields unique by getting the “profile id” and “answer id” from a while-row, and adding it to the class of the answer section.

My problem: When I press the “Answer to the comment”-button, it still toggle’s all the other answer-sections, even though just ONE class is suppose to appear. And I have made sure that the class of the section is unique, and they all have the “display:none;”-style applied to them. I just think that it’s weird that the other classes that has other ID’s also appear when I click the button. It should only be able to show the exact section that is unique from the other classes I believe? I hope you guys understand what I am trying to type - and sorry for some bad grammars. Norwegian guy typing ???

Some of my code:

[code]


Svar på kommentaren


<?php
}
?>


<?php
$birthDate = $answers_poster_row[‘birth’];
$tz = new DateTimeZone(‘Europe/Brussels’);
$shout_age = DateTime::createFromFormat(‘d/m/Y’, $birthDate, $tz)
->diff(new DateTime(‘now’, $tz))
->y;

echo ’
‘;
?>





<?php
if ($_GET[‘section’]==‘question’)
{
echo ‘
’;
}
else
{
echo ‘
’;
}
echo ’
Tid siden hendelse
‘;
echo ‘’;
echo ‘’;
echo ‘’.$answers_poster_row[‘username’].’
svarte:
’;
echo $answers_row[‘answer’];
?>
<?php
echo ’
'; ?>
Skriv ditt svar til kommentaren her:

[/code]

Anyways; thanks in advance! And I hope that any of you people can help me with my PHP issue.

seems more like a JS issue than a PHP issue.

Could you try to recreate it on jsfiddle? Just include the basic html/js that’s needed (the toggle switches and a couple of comments), and add jquery in the left sidebar.

would be easier to help with a (not) working example of what you’re describing

regards from a fellow norwegian :wink:

Ahh… Ofcourse. There must be something with the JS.

I will try to recreate the code as you said, and see if I can resolve the problem through JSFiddle!
Haha, sometimes I just need a little bump in the back as a reminder on how to remember those methods…
Anyways, I will post an update whether this works out or not.

Thank you, neighbour!

I tried doing kind of the same thing in JSFiddle. This worked out fine. Fiddlecode: gacyq8L3. Since I can’t post link’s here yet.
Can the problem be the while function that retrieves the data from the database in rows? Hmm… But I still can’t quite get it, because they still have different class ID’s according to the sourcecode.

I was trying to post a picture, but this didn’t seem to be “available”.

There must be something pretty simple I am missing out on here…

Bumping this, hoping that anyone can help me out on this one :slight_smile:

Hopefully this will help you : http://jsfiddle.net/Strider64/4ro0fyeb/1/

Me bad, I didn’t ready your original question correctly, but I work on that. However, you might be able to do something with the above.

still not there, but this is more what you’re looking for: http://jsfiddle.net/Strider64/m3af0gbg/

Thank you so much! I will try to make it work, and post an update on this.

Sponsor our Newsletter | Privacy Policy | Terms of Service