Question: I am writing javascript to my web pages, but there is a number of functions and loops, that i think are running in all pages, so the first one is running and failing on the second page. Because of this, the javascript function on the second page is not running.

Can anyone give me an idea of how to create page-specific functions or check the availability of an id? I don't use any frameworks.

thanks in advance.

my javascript code is :

```
window.onload = function(){  
   var yellows = document.getElementById('magazine-brief').getElementsByTagName('h2');  
   var signUp = document.getElementById('signup-link');      
    function animeYellowBar(num){  
      setTimeout(function(){  
          yellows[num].style.left = "0";  

          if(num == yellows.length-1){  
              setTimeout(function(){  
                  signUp.style.webkitTransform = "scale(1)";  
              },num * 250);  
          }  
      }, num * 500);  
    }
    for (var i = 0; i < yellows.length; i++){  
      animeYellowBar(i);  
    }

    alert("alert second page");  
}

```

in this code, the alert message not working on second page. any idea?

Answer: 
The code takes the string `optarg` and, treating it as hex, converts it to an integer and stores it in iMask.

If you remove the std::hex modifier you can parse the input as decimal. However, I usually use boost's lexical\_cast for this. For example:

```
int iMask = boost::lexical_cast< int >( strMask );

```
This code uses [manipulators](http://www.cplusplus.com/reference/iostream/manipulators/) to set the stream to expect integers to be read in base 16 (hexadecimal, using the digits 0123456789ABCDEF), then extracts a hexadecimal number from the string, storing it in iMask, and uses another manipulator to set the string stream back to the default of expecting integers to be written in decimal form.