user3304016
user3304016

Reputation: 45

html table make javascript run automatically in <td> tag

I have a part of a table as follows:

//If (condition is true)
{

 <td width="60" id="myIDValue"  bgcolor="#FFFFFF" onclick="GetScope(id)" onload="HideSubmit()">1 </td>

}
else
{
 <td width="60" id="myIDValue"  bgcolor="#000000" onclick="GetScope(id)">2 </td>

}

My OnClick function works fine but I'm looking to also run my Hidesubmit function if one of the top tds are created ( if the condition is true)

My function:

<script>
function HideSubmit() {
    document.getElementById("SubmitButton").style.display = 'none';
}

Any help is appreciated, thanks.

Upvotes: 2

Views: 5086

Answers (3)

ucdream
ucdream

Reputation: 691

the onload event are only supported by following elements: body, frame, frameset, iframe, img, link, script

there is other way to resolve your problem.

<td width="60" id="myIDValue" bgcolor="#FFFFFF" onclick="GetScope(id)" condition="true">1 </td>

window.onload = function() {
    var el = document.getElementById('myIDValue');
    if (el.getAttribute('condition') === 'true') {
        HideSubmit();
    }
}

Upvotes: 3

Peshal
Peshal

Reputation: 1518

You need to check if the ID exists when the document loads and if id exists call the function. You can use javascript to achieve this. Add this to you script tag.

    window.onload=function(){
    var myTd = document.getElementById('myIDValue');
    if(myId!=null) {
    HideSubmit();
    }
    };

Upvotes: 0

ltalhouarne
ltalhouarne

Reputation: 4636

Try the following: $(document).ajaxComplete(hideSubmit);

Upvotes: 0

Related Questions