Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    pass id from href link & toggle on off

    i have a little function that uses a checkbox to turn off or on a map layer

    Code:
    function toggleGeoXML(id, checked) {
      if (checked) {
        var geoXml = new GGeoXml(layers[id].url);
        layers[id].geoXml = geoXml;
    
        if (layers[id].zoom) {
          map.setZoom(layers[id].zoom);
        } else {
          map.setZoom(1);
        }
        if (layers[id].lat && layers[id].lng) {
          map.setCenter(new GLatLng(layers[id].lat, layers[id].lng));
        } else {
          map.setCenter(new GLatLng(39.909736,-35.859375));
        }
        map.addOverlay(geoXml);
      } else if (layers[id].geoXml) {
        map.removeOverlay(layers[id].geoXml);
      }
    }
    i'm trying to use an image instead of a checkbox (can be a styled button or a link)

    the problem is trying to get rid of the "checked" part of the function and integrate it with a normal link but still toggle it off and on

    this check box input works

    Code:
    <input type="checkbox" value="" id="name id of layer" onClick="toggleGeoXML(this.id,this.checked)" />
    ive seen loads of ways of showing and hiding layers but nothing that seems relevant to this instance

    ive tried loads of different things like

    Code:
    <a id="name id of layer" href="#"  onClick="toggleGeoXML(this.id,this.checked);return false;">on/off</a>
    also removing the checked part in the function - the link turns layer on but then wont turn it off

    ie:
    Code:
    <a id="name id of layer" href="#"  onClick="toggleGeoXML(this.id);return false;">on/off</a>
    i'm sure its something stupid but ive been looking at this all afternoon and just keep going round in circles

    thx

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    id="name id of layer"
    Is that your actual code? Then remove the spaces from the value of id attribute, since it's invalid.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    no its not - i just used that instead of the actual id name - its a single text string with no spaces - as i said the checkbox form toggles ok but not when i try and use a link

  • #4
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts
    Its but should work messy i will write clean now for you

    onClick="if(typeof(this.checked) == "undefined"){this.checked = true}else if(this.checked){ this.checked = false; }else{ this.checked = true; }toggleGeoXML(this.id,this.checked)"

    PHP Code:
    function mapCheck(obj){
        if(
    typeof(obj.checked) == "undefined"){
            
    obj.checked true
        
    }else if(this.checked){
            
    obj.checked false
        }else{
            
    obj.checked true
        }
        
    toggleGeoXML(obj.id,obj.checked)

    onClick="mapCheck(this);"
    Last edited by barkermn01; 10-28-2010 at 06:45 PM.
    Working towards a Internet where we don't have website just browser applications Kill the Hyper-link and say hello to 3D Games in the browser :)

  • #5
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    works perfectly ! mucho gracious

    not entirely sure how thats constructed but thanks again

  • #6
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts
    Quote Originally Posted by adeibiza View Post
    works perfectly ! mucho gracious

    not entirely sure how thats constructed but thanks again
    Every thing in JavaScript is an object is the best way to explain it in laymen terms lol
    Last edited by barkermn01; 10-28-2010 at 06:49 PM.
    Working towards a Internet where we don't have website just browser applications Kill the Hyper-link and say hello to 3D Games in the browser :)


  •  

    Posting Permissions

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