Jump to content

Recommended Posts

hi

 

i am trying to post hidden type data. the problem is when i press click link then it should display that postid for which user clicks click link. but it only displays the first post's postid

 

here is my code

<?php
$connect = mysql_connect("localhost","user","pass");
$db = mysql_select_db("db");
$get_data = mysql_query("SELECT * FROM posts");

while($row = mysql_fetch_assoc($get_data)) {
$postid = $row['postid'];
$post = $row['post'];
?>
    <div>
    <?php
echo $postid."<br>".$post;
?>
    <input type="hidden" name="click" id="click" value="<?php echo $postid ?>" />
    <a class="click_here" href="#">Click</a>
    </div>
    <?php
}
?>
<script type="text/javascript" src="lib/jquery-1.4.min(Production).js"></script>
<script>
$(document).ready(function() {
$('.click_here').click(function() {
	var clickval = $('#click').val();
	alert(clickval);
});
});
</script>

Link to comment
https://forums.phpfreaks.com/topic/199669-need-help-in-posting-hidden-type-data/
Share on other sites

So the page doesn't reload when the link is clicked, it's handled by JQuery, correct? If that's the case, there should be a way to do this without needing to pass the value at all (I'd imagine). My javascript skills end at 'alert' though, so I'll not be able to help with that part of it.

i want to do something like this

<?php
$connect = mysql_connect("localhost","user","pass");
$db = mysql_select_db("db");
$get_data = mysql_query("SELECT * FROM posts");

while($row = mysql_fetch_assoc($get_data)) {
$postid = $row['postid'];
$post = $row['post'];
?>
    <div>
    <?php
echo $postid."<br>".$post;
?>
    <style>
.reply_container<?php echo $postid; ?> {
	display: none;
}
</style>
    <input type="hidden" name="click" id="click" value="<?php echo $_SESSION['postid']; ?>" />
    <a class="click_here" href="#">Click</a>
    </div>
    <div class="reply_container<?php echo $postid; ?>">
    <form action="" method="post">
        <textarea name="reply" id="reply" rows="3" cols="40"></textarea>
        <input type="button" name="replybtn" id="replybtn" value="reply" />
    </form>
    </div>
    <?php
}
?>
<div class="display"></div>
<script type="text/javascript" src="lib/jquery-1.4.min(Production).js"></script>
<script>
$(document).ready(function() {
$('.click_here').click(function() {
	var clickval = $('#click').val();
	alert(clickval);
	$('.reply_container' + clickval).css('display','block');
});
});
</script>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.