只想问一个关于使用 jquery 传递值并将其分配到表单隐藏文本框中的问题。这是我的代码,希望你能帮助我。
**homepage.php**
<?php
$cat_id = $row['salescatid'];
?>
<input type="button" name="add_comment" data-value="<?php echo $cat_id; ?>" value="Add Comment" class="comment" />
.
.
<div id="comment_category">
<!-- DISPLAY COMMENT HERE -->
</div>
<?php echo form_open('CATEGORY_CONTROLLER/INSERT_COMMENT'); ?>
<div id="comment_add" style="display: none;">
<input type="hidden" value="" name="cat_id" /> //Here's the problem how can i get the value from my jquery?
<input type="hidden" value="sales_category" name="type"/>
<label>Write your comment</label><br />
<textarea name="comment_category" style="width: 50%; resize: none;"></textarea><br />
<input type="submit" value="COMMENT" class="btn btn-primary btn-SMALL"/>
</div>
<?php echo form_close(); ?>
.
.
.
//Here's my jquery
$(".comment").click(function(){
var id = $(this).attr('data-value'); //This is the value of the button, problem is how to pass it in my comment form?
$("#comment_add") .show();
//alert(id);
});
请帮帮我。谢谢。