Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

body onClick

Status
Not open for further replies.

micawber

Programmer
Dec 10, 2002
71
GB
On my asp page i have the following:
Code:
<body onClick="AJAXPremium();" class="mainnav">
I have introducted a hint system for my form input fields that works when I remove onClick="AJAXPremium();" from the body tag but doesn't work when it is there. i.e
<body class="mainnav">
The problem is i need both to work!

Any ideas?

Thanks
 

They are attached via span tag after the inputs:
Code:
<span class="hintleft">Enter your first name<span class="hint-pointer">&nbsp;</span></span>

i have a file called inc_hints.js with the functions for the hints.
i think the body onload is overwritten by this but don't know a way around it.

Code:
function addLoadEvent(func)
{
    // alert('addLoadEvent()');
    var oldonload = window.onload;
    if (typeof window.onload != 'function')
    {
        window.onload = func;
    }
    else
    {
        window.onload = function()
        {
            oldonload();
            func();
        }
    }
}

function prepareInputsForHints()
{
	// alert('prepareInputsForHints()');
    var inputs = document.getElementsByTagName("input");
    for (var i = 0; i < inputs.length; i++)
    {
        // test to see if the hint span exists
        if (inputs[i].parentNode.getElementsByTagName("span")[0])
        {
            // the span exists on focus show the hint
            inputs[i].onfocus = function()
            {
                this.parentNode.getElementsByTagName("span")[0].style.display =
                    "inline";
            }
            // hide the hint
            inputs[i].onblur = function()
            {
                this.parentNode.getElementsByTagName("span")[0].style.display =
                    "none";
            }
        }
    }
    // repeat the same tests as above for selects
    var selects = document.getElementsByTagName("select");
    for (var k = 0; k < selects.length; k++)
    {
        if (selects[k].parentNode.getElementsByTagName("span")[0])
        {
            selects[k].onfocus = function()
            {
                this.parentNode.getElementsByTagName("span")[0].style.display =
                    "inline";
            }
            selects[k].onblur = function()
            {
                this.parentNode.getElementsByTagName("span")[0].style.display =
                    "none";
            }
        }
    }
}
addLoadEvent(prepareInputsForHints);
 
i've now sorted this, just had to move the the <script> tags for the hints out of the head section into the body section.
thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top