views:

105

answers:

2
<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>
+1  A: 

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.

Pekka
I have edited the main post, I don`t know why I couldn`t add html here.About the row[i] line, I think it`s ok this way because the id is corectly passed to the JS function
Claudiu
I edited the answer.
Pekka
I don`t understand what that has to do with the thing that I don`t receive value through document.getElementById('addEdit')
Claudiu
Do you have one addEdit per row? That won't work, an ID has to be unique. Best would be to do use an ID like `addEdit_row_30129`
Pekka
I`ve followed your advice and my problem is solved, THANK YOU German guy
Claudiu
You're welcome! :)
Pekka
+1  A: 

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

Kris Krause
I`ve modified, thank you for the jslint.com site ;)
Claudiu