0

This is my JavaScript code:

function selectRow(objTR) {
    for (i = 0; i < ddlModalityList.options.length; i++) {
        if (ddlModalityList.options[i].text == objTR.cells[1].innerText.trim()) break;
    }

    ddlModalityList.options[i].selected = true;
    txtSSAETitle.value = objTR.cells[2].innerText.trim();
    txtSSName.value = objTR.cells[3].innerText.trim();
}

This is repeater code. On row click I am passing id of tr and displaying respective td value in respective dropdownlist and textboxes. This code works fine in IE but fails in Mozilla Firefox.

<tr onclick="selectRow(this);">   
    <td class="csstablelisttd" style="display: none;" >
        <%#Eval("Acq_Modality_ID")%>
    </td>                     
    <td class="csstablelisttd" >                            
        <asp:Label ID="lblModality" runat="server" Text='<%#Eval("Modality")%>'></asp:Label>
    </td>

    <td class="csstablelisttd">
        <asp:Label ID="lblSchdledStAETitle" runat="server" Text='<%#Eval("Scheduled_Station_AE_Title")%>'></asp:Label>
    </td>
    <td class="csstablelisttd">
        <asp:Label ID="lblSchdleStationAEName" runat="server" Text='<%#Eval("SCHEDULED_STATION_NAME")%>'></asp:Label>
    </td>
</tr>
Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107
harsh
  • 109
  • 1
  • 6
  • 22
  • 2
    Please start putting some effort into formulating your questions. Code is **not** the question, explain the problem in words **first**. Only put the **relevant** code into your question - e.g. if it is a client-side problem then ASP code is absolutely irrelevant, post the generated HTML code if necessary (here it isn't). And indent your code properly so that people can read it! – Wladimir Palant May 03 '12 at 11:21

5 Answers5

7

Firefox does not support innerText. You can use textContent instead. However, older IE does not support textContent, so you'll need to use one and fall back to the other.

function getInnerText(el) {
    return el.textContent || el.innerText;
}

Note that they're not identical, but for your purposes it will be fine.

Community
  • 1
  • 1
Tim Down
  • 318,141
  • 75
  • 454
  • 536
  • txtSSAETitle.value = objTR.cells[2].textContent.trim(); Error: 'cells.2.textContent' is null or not an object//In IE //AND in mozilla also not working – harsh May 03 '12 at 09:56
  • @harsh: In that case, that cell does not exist. `textContent` is definitely implemented in Firefox. – Tim Down May 03 '12 at 09:59
  • what exactly i have pass to function because i am getting text from td (cell of tr)and showing in respective textbox and ddl – harsh May 03 '12 at 10:04
  • @harsh: `getInnerText(objTR.cells[2])`, although obviously you need to be sure the cell exists. – Tim Down May 03 '12 at 10:07
  • txtSSAETitle.value= getInnerText(objTR.cells[2]); function getInnerText(el) { return el.textContent || el.innerText; }//this works in IE but not in firefox – harsh May 03 '12 at 10:10
  • @harsh: It does work in Firefox. Check that your table cell exists before calling the function. The problem may be in the `cells` collection: there could be (although I don't know) a difference in browser handling of hidden table cells. – Tim Down May 03 '12 at 10:13
  • Tim:cell is exist and works in IE properly..but in firefox failure – harsh May 03 '12 at 10:16
2

Use innerHTML instead of innerText. InnerText will not work in FF. innerHTML will work on both of them.

http://forums.asp.net/p/1228392/2210082.aspx

Anand
  • 21
  • 1
1

Firefox does not support innerText.. you should use jquery so that you dont need to care about the difference in browers implementation
so using jquery your code would be

function selectRow(objTR) {
    for (i = 0; i < ddlModalityList.options.length; i++) {
        if (ddlModalityList.options[i].text == $(objTR).children('td').eq(1).html().trim()) break;
    }

    ddlModalityList.options[i].selected = true;
    txtSSAETitle.value = $(objTR).children('td label').eq(2).html().trim();
    txtSSName.value = $(objTR).children('td label').eq(3).html().trim();
}

im leaving the ddlModalityList as it is because i dont know what it is.

Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107
Parv Sharma
  • 12,581
  • 4
  • 48
  • 80
0
function selectRow(objTR) {
    for (i = 0; i < ddlModalityList.options.length; i++) {
        if (ddlModalityList.options[i].text == $(objTR).children('td').eq(1).html().trim()) break;
    }

    ddlModalityList.options[i].selected = true;
    txtSSAETitle.value = $(objTR).children('td label').eq(2).html().trim();
    txtSSName.value = $(objTR).children('td label').eq(3).html().trim();
}
Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107
0

document.getElementById('InputText').innerHTML.replace(/<.+?>/gim,''));