Reputation: 8369
I have a page settings.php in codeigniter whose controller is member.php. I have a link 'Movie Settings' in settings.php and on clicking it I want to show a div and hide another div.
In settings.php, I have this line:
<?php echo anchor('member/settings', 'Movie Settings', array('onClick' => "moviesetting()"));
settings.php
<div class="mainsettingdiv">
<div class="leftsettingdiv">
Profile Settings
<br>
<?php echo anchor('member/settings', 'Movie Settings', array('onClick' => "moviesetting()"));
?>
</div>
<div class="rightsettingdiv" id="profilediv">
<b>Profile Image Visibility</b> <br>
<?php echo form_radio('imageset','1')?> Public
<?php echo form_radio('imageset','2')?> Friends Only
<?php echo form_radio('imageset','3')?> Private
<br><br>
<b>Email Visibility</b> <br>
<?php echo form_radio('emailset','1')?> Public
<?php echo form_radio('emailset','2')?> Friends Only
<?php echo form_radio('emailset','3')?> Private
<br><br>
<b>Address Visibility</b> <br>
<?php echo form_radio('addressset','1')?> Public
<?php echo form_radio('addressset','2')?> Friends Only
<?php echo form_radio('addressset','3')?> Private
<br><br>
<b>Mobile Number Visibility</b> <br>
<?php echo form_radio('mobileset','1')?> Public
<?php echo form_radio('mobileset','2')?> Friends Only
<?php echo form_radio('mobileset','3')?> Private
<br>
<?php
$js = 'onClick="saveprofilesetting('.$id.',\''.base_url().'\')"';
echo form_button('save','Save',$js);?>
</div>
<div class="moviesettings" style="display:none" id="moviediv">
</div>
</div>
and my javascript function:
function moviesetting()
{
$("#moviediv").show();
$("#profilediv").hide();
}
But as I am using anchor()
the page is getting reloaded on clicking. So the javascript function is not seem to be worked. How can I remove the href from the anchor()
and make it work?
I tried with adding #
and javascript:void(0)
in anchor()
, but in both cases it is getting redirected to index page. I don't want redirection. Can anyone help me to solve this?
Thanks in advance.
Upvotes: 3
Views: 944
Reputation: 8838
Add return false;
in your js function to avoid page reload
function moviesetting()
{
$("#moviediv").show();
$("#profilediv").hide();
return false;
}
Upvotes: 1