Jump to content

need help in posting hidden type data


doforumda

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>

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.