SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Addict tlacaelelrl's Avatar
    Join Date
    Apr 2011
    Location
    Mexico city, Mexico
    Posts
    353
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    javascript checkbox

    I have made an anchor look like a checkbox with this:

    Code HTML4Strict:
    <style type="text/css" >
    .checkbox{
    	display: block;
            width: 20px;
            height: 20px;
    	position: relative;
            right: -540px;
            top: -25px;
    	overflow:hidden;
    	}
    .checkbox_u{	
    	background-image:url('unchecked.png');
    	background-repeat:no-repeat;
    	}
    .checkbox_c{
    	background-image:url('checked.png');
    	background-repeat:no-repeat;
    	}
    </style>
    <a class="checkbox checkbox_u" ref="#"  target="unchecked" onmousedown="checked_(this);return false;" />  </a>

    and the checked_() function is this

    Code JavaScript:
    function checked_(checked){
    	if(checked.target == 'unchecked'){
    		checked.className = 'checkbox checkbox_c';
    		checked.target = 'checked'
    		}
    	else{
    		checked.className = 'checkbox checkbox_u';
    		checked.target = 'unchecked'
    		}
    	}

    the function changes the className, however sometimes I have to click on it several times in order for it to respond, is there something I can do to make it respond immediately?

    By the way, I do need to make it like this, because I could not position the check-box where I needed it to be.
    I also tried with span instead of a and using the class attribute inside the function but I get the same problem

    This is the function when I tried span:
    Code JavaScript:
    function checked_(checked){
    	if(checked.className == 'checkbox checkbox_u'){
    		checked.className = 'checkbox checkbox_c';
    		}
    	else{
    		checked.className = 'checkbox checkbox_u';
    		}
    	}

    And this is what the span looks like:
    Code HTML4Strict:
    <span class="checkbox checkbox_u" onmousedown="checked_(this);" /></span>

  2. #2
    SitePoint Addict tlacaelelrl's Avatar
    Join Date
    Apr 2011
    Location
    Mexico city, Mexico
    Posts
    353
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •