function clicker(){ var thediv=document.getE...">

Onclick calls two functions at the same time?

here is my code ..

<script type="text/javascript">
function clicker(){

    var thediv=document.getElementById('downloadoverlay');
    if(thediv.style.display == "none"){
        thediv.style.display = "";
        thediv.appendChild()
    return false;
    }
}
function clicker1(){
    var thediv1=document.getElementById('downloadbox');
    if(thediv1.style.display == "none"){
        thediv1.style.display = "";
        thediv1.appendChild()

    return false;
    }
}



</script>

      

when the button is pressed .. the event should call two functions at the same time .. help .. ??

+3


source to share


5 answers


Add handlers unobtrusively from your script. Something like:



function addHandler(etype, el,handlerFunction){
  if (el.attachEvent) {
   el.attachEvent('on' + etype, handlerFunction);
  } else {
   el.addEventListener(etype, handlerFunction, false);
  }
}
var myButton = document.getElementById('mybutton');
addHandler('click', myButton, clicker);
addHandler('click', myButton, clicker1);

      

+2


source


Yes you can if you attach an event listener: IE , other browsers .

Just keep in mind that both of them will not end at the same point, and it would be possible to "cut" if the site is redirected, before the second function is executed.



In addition, in this case, I would set a CSS class to the tag that contains both #downloadoverlay

, and so #downloadbox

. Instead of accessing the object directly style

.

+1


source


Just write one function that calls both. For example, you can write

function onClick() {
  clicker();
  clicker1();
}

      

And install onclick="return onClick();"

on the item you are interested in.

+1


source


Just make another function to call both of them at the same time.

function callClickers(){
    clicker();
    clicker1();
}

      

Now add this to your onclick button

+1


source


You can call two functions at once for an event onClick

    <button type="submit" id="mySubmit" onClick=" clicker(); clicker1()">Search</button>

      

0


source







All Articles