Jump to content

nogray

Members
  • Posts

    930
  • Joined

  • Last visited

Posts posted by nogray

  1. If you check the NoGray JavaScript library, you'll find a whole set of animation options. Also there is a set opacity function.

     

    Or you can do use the set opacity as a stand alone with a setTimeout to hide and show the divs.

    
    // pass the object to the function using
    // something like document.getElementById()
    
    // IE might need the object to have absolut positioning
    function setOpacity(obj, val){
    // checking if the browser is Opera
    var is_Opera = (window.navigator.userAgent.search("Opera") != -1);
    
    // checking if the browser is IE
    var is_IE = ((window.navigator.userAgent.search("MSIE") != -1) && !is_Opera);
    
    if (is_IE){
    	obj.style.filter ="progid:DXImageTransform.Microsoft.BasicImage(Opacity="+val+")";
    }
    else {
    	obj.style.MozOpacity = val;
    }
    obj.style.opacity = val;
    }
    
    

     

    The val should be between 0 to 1

  2. You need to initiate two Date variables to get the different times, here is an example

     

    <script language="javascript">
    function do_something(){
    	// start timer
    	var st_time = new Date();
    
    	// do stuff
    	var foo = 0;
    	for (i=0; i<1000; i++){
    		foo += foo * i;
    	}
    
    	// end timer
    	var en_time = new Date();
    
    	alert(st_time.getTime()+" "+en_time.getTime());
    }
    
    do_something();
    </script>
    

  3. I haven't tested this, but you'll need to set a boolean type variable on the body element. When the mouse is down, you set the variable value will be true and when the mouse is over an object, you can check the variable value.

  4. Here is a few function that will help you select any option based on the value, text or index

    <script language="javascript">
    
    // select an option based on value
    function selSelectValue(sel, val){
    var op = sel.childNodes;
    var selIndex = 0;
    for(i=0; i<op.length; i++){
    	if (op[i].tagName == "OPTION"){
    		if (op[i].value == val) {
    			sel.selectedIndex = selIndex;
    			i = op.length+1;
    		}
    		selIndex++;
    	}
    }
    }
    
    // select an option based on text
    function selSelectText(sel, val){
    var op = sel.childNodes;
    var selIndex = 0;
    for(i=0; i<op.length; i++){
    	if (op[i].tagName == "OPTION"){
    		if (op[i].innerHTML == val) {
    			sel.selectedIndex = selIndex;
    			i = op.length+1;
    		}
    		selIndex++;
    	}
    }
    }
    
    // select an option based on index
    function selSelectIndex(sel, val){
    sel.selectedIndex = val;
    }
    </script>
    <select id="sel" name="sel">
    <option VALUE="value1">Hotmail</option>
    <option VALUE="value2">Gmail</option>
    <option VALUE="value3">Yahoo</option>
    </select>	
    <br />
    Text:<br />
    <input type="text" id="val" />
    <br /><br />
    <button onclick="selSelectValue(document.getElementById('sel'), document.getElementById('val').value);">Select by Value</button> enter value1, value2 or value3<br />
    <button onclick="selSelectText(document.getElementById('sel'), document.getElementById('val').value);">Select by Text</button> enter Hotmail, Gmail, Yahoo<br />
    <button onclick="selSelectIndex(document.getElementById('sel'), document.getElementById('val').value);">Select by Index</button> enter 0, 1, 2
    

  5. You gotta wait until the second page loads before you access it's elements. You can use the script inside the whatever.html page to get the code from the parent window once it loaded.

    in whatever.html
    <script language="javascript">
    function ini_page(){
         document.getElementById('theDiv').innerHTML = opener.getConent();
    }
    </script>
    <body onload="ini_page();">
    

    in the main page
    function getContent(){
         return theTable;
    }
    

     

    Just make sure theTable is a global variable.

     

    Code untested.

  6. use a more common AJAX approch to avoid any problems. The XMLHttpRequest works in IE 7 and other browsers, while ActiveXObject("Msxml2.XMLHTTP") only works in IE 6 and below

     

    something like this will be a better choice

    var xmlHttp;
    try{
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
    catch (e) {
    // Internet Explorer
    try{
    	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e){
    	try {
    		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    	}
    	catch (e){
    		alert("Your browser does not support AJAX!");
    		return false;
    	}
    }
    }

  7. Here is an example on how to access the selected option value. You cannot have any events on the option directly.

     

    I used a javascript array for the data, but most likely you would wanna use ajax if you have a gain list.

     

    good luck

     

    <script language="javascript">
    var txt = new Array();
    txt['option 1 value'] = "option 1 description";
    txt['option 2 value'] = "option 2 description";
    txt['option 3 value'] = "option 3 description";
    txt['option 4 value'] = "option 4 description";
    txt['option 5 value'] = "option 5 description";
    
    function show_txt(val){
    	if (val != "")
    		document.getElementById('description').innerHTML = txt[val];
    
    	else
    		document.getElementById('description').innerHTML = "";
    }
    </script>
    <select onchange="show_txt(this.value);">
    <option value="">Select</option>
    <optgroup label="Hello">
    	<option value="option 1 value">Option 1</option>
    	<option value="option 2 value">Option 2</option>
    	<option value="option 3 value">Option 3</option>
    </optgroup>
    <option value="option 4 value">Option 4</option>
    <option value="option 5 value">Option 5</option>
    </select>
    <div id="description"></div>
    

  8. The problem is the lightboxes out there only look at the HTML code when the page loads, so if you using AJAX to load the page, the lightbox won't know it has to look for the links, therefore not working. To fix that, look at your lightbox script and find the initiating function and find what events the script add to the links. You can call that function when the AJAX page loads as well.

  9. If you running the script from your own pc, make it an HTA file (HTML application)

    more on hta http://msdn2.microsoft.com/en-us/library/ms536496.aspx

     

    This will give you the security clearness to write to your own pc (if you have Norton antivirous, you'll get a warrning).

     

    If it's live, than you can't write using front end script, you can use JScript.net, but thats works on the server side as well.

     

    The issue is if someone gained access to your page that write the files, they can add a script to the URL query to comprimize your site.

     

  10. you can add a "Check if unique" link next to the field, so when they finish typing, they can click on that and a small pop-up (or ajax) will check if the username is unique.

     

    Also, you can submit the form to a hidden iframe that will either process the form and than redirect the parent window, or will print out a javascript alert with the errors (this way they don't leave the form after they submit unless it's valid).

  11. The filesystemobject is only an IE object and only works on .hta (HTML application) file.

     

    You can't write to the server using JavaScript because it's a huge security issue (anyone can hack your site by writing server side files).

     

    User a server side script to write the file such as PHP or ASP,

  12. both these scripts work fine, make sure you don't have an error somewhere else in your code that stops the script from working. In firefox, after you get the error click on "Tools" from the top menu (next to File, Edit, View) and select "Error Console" (or Javascript Console if you have an older version).

     

    This should let you know where is your error.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.