Welcome Guest, Not a member yet? Register   Sign In
[ask] how to create link that can disable another link?
#1

[eluser]dinnar[/eluser]
hi guys, i need your help
how to create link that can disable another link?

e.g:
i have 3 links: link_a, link_b, link_c
if i click link_c, link_a and link_b become disable....

how to do that?
#2

[eluser]ayukawaa[/eluser]
There could be better ways, but this should work using unobtrusive JavaScript with jquery:

Code:
<html>                                                                  
<head>                                                                  
<scr_ipt type="text/javascript" src="jquery.js"></scr_ipt>          
&lt;style type="text/css"&gt;
a.disabled_class,
a.disabled_class:link,
a.disabled_class:hover,
a.disabled_class:active
{
    color:gray;
}
&lt;/style&gt;
<scr_ipt type="text/javascript">
&lt;!--
$(
    function()
    {

        $("#href_one").click
        (
            function(event)
            {
                event.preventDefault();
                $("#href_two").toggleClass("disabled_class");
                $("#href_three").toggleClass("disabled_class");
            }
        );
    
        $("#href_two").click
        (
            function(event)
            {
                if($(this).hasClass('disabled_class'))
                {
                    event.preventDefault();
                }
            }
        );

        $("#href_three").click
        (
            function(event)
            {
                if($(this).hasClass('disabled_class'))
                {
                    event.preventDefault();
                }
            }
        );
    
    }
);
//--&gt;
</scr_ipt>
&lt;/head&gt;                                                                
&lt;body&gt;                                                                  

<br /><a href="href_one" id="href_one">href_one</a>
<br /><a href="href_two" id="href_two">href_two</a>
<br /><a href="href_three" id="href_three">href_three</a>

&lt;/body&gt;                                                                
&lt;/html&gt;

Notice that I do not touch the links.

The first link toggle the class to the other links.
When click on the other links if it hass the disabled class, stop.

^_^
#3

[eluser]mihaibaboi[/eluser]
I came here wanting to propose jQuery. It seems @ayukawaa beat me to it. Give the code a try, I think this is your best bet. Smile
#4

[eluser]dinnar[/eluser]
how to do it in codeigniter???
#5

[eluser]web-johnny[/eluser]
You can simply try the code of ayukawaa in a view . For example to the controller (application/controllers) you can do this
Code:
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {
    public function index()
    {
        $this->load->view('custom_page');
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
Where the custom_page.php is on the folder application/views. You can try the online link of jquery http://ajax.googleapis.com/ajax/libs/jqu...ery.min.js . Its easy have a try
#6

[eluser]mihaibaboi[/eluser]
[quote author="dinnar" date="1305177780"]how to do it in codeigniter???[/quote]

It doesn't matter if your'e using CodeIgniter or not. The script is inline so you can just put it in your view.

Just treat your view as you normally would a php/html file.
#7

[eluser]dinnar[/eluser]
i want to make 3 link like:
link_a link_b link_c

usually i create link in controller like this:

$data['link'] = array('link_add'=>anchor('somefile/add/', 'link_a', array('class' => 'add')),
anchor('somefile/delete/', 'link_b', array('class' => 'delete')),
anchor('somefile/disable_another_link/', 'link_c', array('class' => '?')));

what should i fill in class link_c ???

i hope when i click link_c, link_a and link_b become disable
#8

[eluser]mihaibaboi[/eluser]
I'm not sure I understand your problem. The code that @ayukawaa provided is non-intrusive. You don't need to do anything to the links, other that provide the id's specified in te snippet.

All other attributes are up to you, as they do not affect the jQuery script.




Theme © iAndrew 2016 - Forum software by © MyBB