[eluser]Unknown[/eluser]
I was thinking hard on how to post this question.
this maybe requires some scriptaculous+prototype since im using that both.
the example is here.
http://abigoroth.inter.net.my/code/
the
view text is clickable & a ajax updater function has been trigger.
as u can see the main function is
code
this is the blog_view.php
Code:
<head>
function view_cmt(id)
{
var url = '<?=site_url()?>/blog/comments/'+id;
var myAjax = new Ajax.Updater( 'comments' + id, url, { method: 'get'});
}
function close_cmt(id)
{
var url = '<?=site_url()?>/blog/close/'+id;
var myAjax = new Ajax.Updater( 'comments' + id, url, { method: 'get'});
}
</head>
<title><?=$title;?></title>
<h1><?=$heading;?></h1>
<? foreach($query->result() as $row): ?>
<h3><?=$row->title;?></h3>
<p><?=$row->body;?></p>
<div id="<? echo "comments$row->id"; ?>" >
<? echo "<a onClick=view_cmt($row->id);>view</a> "; ?>
</div>
<!------p><?=anchor('blog/comments/'.$row->id, 'Comments');?></p--------->
<hr>
<? endforeach; ?>
this is my comment_view.php
Code:
<title><?=$title;?></title>
<head>
<!------script type="text/javascript" src="<?=base_url()?>src/js/func.js">
function add_cmt(id)
{
// var author = $F('author');
// var body = $F('BODY');
// [removed](body);
// var pars1 = 'BODY='+body+'&author;='+author;
var url = '<?=site_url()?>/blog/comment_insert/'+id+'/asdsd/ontahla';
var myAjax = new Ajax.Updater( 'cmtField' + id, url);
}
</head>
<h3><?=$heading;?></h1>
<div id="<? echo "cmtField".$this->uri->segment(3); ?>">
<? foreach($query->result() as $row): ?>
<h3><?=$row->author;?></h3>
<p><?=$row->body;?></p>
<hr>
<? endforeach; ?>
</div>
<?=form_open('blog/comment_insert');?>
<?=form_hidden('entry_id', $this->uri->segment(3));?>
<p><textarea name="BODY" rows="10"></textarea></p>
<p><input type="text" name="author" /></p>
<p><input type="submit" value="Submit Comment" onClick="add_cmt(<?=$this->uri->segment(3);?>);" /></p>
<p><input type="button" value="Close" onClick="close_cmt(<?=$this->uri->segment(3);?>);"/></p>
</form>
the main objectives is, how to insert comment without refreshing the page.
as you can see my javascript
Code:
function add_cmt(id)
{
// var author = $F('author');
// var body = $F('BODY');
// [removed](body);
// var pars1 = 'BODY='+body+'&author;='+author;
var url = '<?=site_url()?>/blog/comment_insert/'+id+'/asdsd/ontahla';
var myAjax = new Ajax.Updater( 'cmtField' + id, url);
}
my $F('input.name.from.form') seems not to be working.
can some1 help.
note:
i did try with the input button without type=submit