Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 22nd, 2006, 06:05 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default javascript blink in innerHTML

I have this setup to display the date in a <td>, however, as it is built with innerHTML can i still apply the blink method to it.
The code below doesnt work for the blinking.
But the JS blink functions and CSS works when i apply it to a font tag outwith the innerHTML?
Code:
function getTheDate(GMToffset)
{
    var orgdate=new Date();
    var year=orgdate.getYear();
    if (year < 1000)
    year+=1900;
    var day=orgdate.getDay();
    var month=orgdate.getMonth();
    var daym=orgdate.getDate();
    if (daym<10)
    daym="0"+daym;
    var dayArr=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
    var monthArr=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
    var time = document.getElementById("time");
    var theDate = new Date();
    var frmtedDate = theDate.getHours();
    var GMTchange;

    time.className = "font4";
    if ((GMToffset!="0")&&(GMToffset!=null))
    {
        var oprtor = GMToffset.slice(0,1);
        if(GMToffset.length>2)
        {
            GMTchange = GMToffset.slice(1,3);        
        }
        else
        {
            GMTchange = GMToffset.slice(1,2);        
        }

        var preFrmtedDate = theDate.getHours();

        if(oprtor=="-")
        {
            frmtedDate = Number(parseFloat(preFrmtedDate)-parseFloat(GMTchange));
        }
        else if(oprtor=="+")
        {
            frmtedDate = Number(parseFloat(preFrmtedDate)+parseFloat(GMTchange));
        }
    }

    var theMinuten = theDate.getMinutes();

    if(parseFloat(frmtedDate)>24)
    {
        day = day+1;
        daym = daym+1;
        frmtedDate = parseFloat(frmtedDate)-24;
    }
    //alert("frmtedDate B4 = " + frmtedDate);
    if(frmtedDate<10)
    {
        //alert("under 10");
        var frmtedDate = "0"+frmtedDate;
        //alert("frmtedDate formatted = " + theFrmtedDate);    
        //frmtedDate = Number(theFrmtedDate);
    }    
    //alert("frmtedDate = " + frmtedDate);
    if(parseFloat(theMinuten)<10)
    {
        theMinuten = "0"+theMinuten;
        //theMinuten = parseFloat(theMinuten);
    }
    time.innerHTML = frmtedDate;    
    time.innerHTML = time.innerHTML + "." + theMinuten + "&nbsp;" + dayArr[day] + ",&nbsp;" + monthArr[month] + "&nbsp;" + daym + ",&nbsp;" + year;

}

<script type="text/javascript">
<!--
var b_timer = null; // blink timer
var b_on = true; // blink state
var blnkrs = null; // array of spans

function blink() {
var tmp = document.getElementsByTagName("font");
if (tmp) {
blnkrs = new Array();
var b_count = 0;
for (var i = 0; i < tmp.length; ++i) {
if (tmp[i].className == "blink") {
blnkrs[b_count] = tmp[i];
++b_count;
}
}
// time in m.secs between blinks
// 500 = 1/2 second
blinkTimer(500);
}
}

function blinkTimer(ival) {
if (b_timer) {
window.clearTimeout(b_timer);
b_timer = null;
}
blinkIt();
b_timer = window.setTimeout('blinkTimer(' + ival + ')', ival);
}

function blinkIt() {
for (var i = 0; i < blnkrs.length; ++i) {
if (b_on == true) {
blnkrs[i].style.visibility = "hidden";
}
else {
blnkrs[i].style.visibility = "visible";
}
}
b_on =!b_on;
}
//-->
</script>    

<script language="javascript">
window.onload=blink;
</script>

<style>
.blink {
font-size: 15px;
color: #000000;
display: inline;
} 
</style>



www.crmpicco.co.uk
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
 
Old February 22nd, 2006, 08:19 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

maybe a better way to put it is
Code:
    time.innerHTML = time.innerHTML + "." + theMinuten + "&nbsp;" + dayArr[day] + ",&nbsp;" + monthArr[month] + "&nbsp;" + daym + ",&nbsp;" + year;
how can i make the 'dot' or 'fullstop' blink? [bold]"."[/bold]

Thanks.

Picco

www.crmpicco.co.uk
 
Old February 23rd, 2006, 05:47 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

If you create your dot within a tag of it's own, you could apply your blink method to that.

HTH,

Chris

 
Old February 23rd, 2006, 10:36 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

yeah, i tried that chris
Code:
"."
its just basically to make it look as if the clock is ticking.........

www.crmpicco.co.uk
 
Old February 23rd, 2006, 11:34 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

You need to call the call the blink() method after you update the innerHTML to rebuild the array of tags getting blinked.

HTH,

Chris

 
Old March 10th, 2006, 06:21 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

unforunately IE doesnt support the javascript blink method

www.crmpicco.co.uk
 
Old March 10th, 2006, 10:31 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Works fine for me. Like I said you just need to call blink() after you add the innerHTML e.g.
Code:
<a href="#" onclick="document.getElementById('myDiv').innerHTML = 'I BLINK!!!';blink();">add blinking innerHTML</a>
...    
<div id="myDiv"></div>
 
Old March 16th, 2006, 01:41 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

thanks Chris, i'll give it a try and get back to you


www.crmpicco.co.uk
 
Old April 3rd, 2006, 06:38 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

yeah that worked fine chris!

www.crmpicco.co.uk
www.ie7.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Blink Datagrid cell data?? vinodjangle ASP.NET 2.0 Professional 1 April 18th, 2008 09:51 AM
Making text blink in a gridview with Javascript. Andrew.Berry Other Programming Languages 6 February 14th, 2008 05:26 PM
Make the browser Blink... slim182 ASP.NET 2.0 Professional 0 March 8th, 2007 09:40 AM
how to blink the minimized window vickyj Classic ASP Basics 0 January 25th, 2005 07:18 AM
Making a label blink levinll VB How-To 2 June 23rd, 2004 12:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.