3

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.

1
  • You're specifying a route as the first argument (Although this is OK, but you need to preventDefault in your javascript) OR just use '#' instead of the route 'member/settings' Commented Mar 5, 2014 at 22:06

1 Answer 1

1

Add return false; in your js function to avoid page reload

function moviesetting()
{ 
    $("#moviediv").show();
    $("#profilediv").hide();
    return false;
}
Sign up to request clarification or add additional context in comments.

3 Comments

you mean as pure html?
did you do any changes apart from my answer?
no just replaced anchor() with <a onclick="moviesetting()">Movie Settings</a>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.