开发者

getElementById().value returns nothing

<td id="'.$row['id'].'"style="display: none;">
    <input id="addEdit" type="text" value="" size="4"/>
</td>
<td>
    <input name="add" value="A" type="submit开发者_运维问答" onClick="addObs('.$row['id'].'); return false;"/>
</td>

.

function addObs(id)
{
    var addEditTD = document.getElementById(id);

    if (addEditTD != null && addEditTD.style.display == 'none')
    {
        addEditTD.style.display = '';
    }

    if (addEditTD.style.display == '' && document.getElementById('addEdit').value != "")
    {
        //some code
        alert(document.getElementById('addEdit').value);
    }
}

I don't receive any value from the 'addEdit' input text, I don't know why, pls help.

this are the "source" lines related to my html tags:

<td id="30129"style="display: none;">
<input id="addEdit" type="text" value="" size="4"/></td>
<td>
<input name="add" value="A" type="submit" onClick="addObs(30129); return false;"/>
</td>


Ah. You are using pure numbers as element IDs, which is not possible. Add something in front, like "row_30129" (to the ID itself and the function calls, of course). Also, add quotes to the addObs() call:

addObs('row_30129');

that should work.


I just ran your javascript through http://www.jslint.com -

Error: Problem at line 5 character 19: Use '!==' to compare with 'null'.

if (addEditTD != null && addEditTD.style.display == 'none')

Implied global: document 3,10,13, alert 13

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜