0

I have a page layout in which I have created HTML table structure. In between, I want to display static text if the td is empty. My code is simple:

<td> 
    <div id="dvCountry">
        <SharePointWebControls:FieldValue FieldName="Country" DisableInputFieldLabel="true" runat="server"></SharePointWebControls:FieldValue></div>
    <div id="dvOffice">,<SharePointWebControls:FieldValue FieldName="Office" DisableInputFieldLabel="true" runat="server"></SharePointWebControls:FieldValue></div>
    <script type="text/javascript">
            var td = document.getElementById("dvCountry");
            if(td.innerText.length == 0){
                td.innerText = "Group";
                var divOffice = document.getElementById("dvOffice");
                divOffice.innerText = "";
            }

    </script>
</td>

The above code is working fine in IE, and Chrome but not working in Firefox.

What am I missing?

Mohemmad K
  • 809
  • 7
  • 33
  • 74
  • Any errors in the console? How does it not work? What have you tried in the field of debugging? – Jite Jun 27 '15 at 10:39
  • http://stackoverflow.com/questions/1359469/innertext-works-in-ie-but-not-in-firefox – Delgan Jun 27 '15 at 10:40
  • check your console for errors and also try console.log(td.innerText.length, td.innerText); to check whether or not firefox is getting a text value. (maybe the linebreak/spaces are causing this issue) alternatively check td.textContent – Sebastian Nette Jun 27 '15 at 10:41

1 Answers1

1

The issue comes from innerText.
See: 'innerText' works in IE, but not in Firefox

You should use jQuery or use innerHTML.

Community
  • 1
  • 1
Delgan
  • 18,571
  • 11
  • 90
  • 141
  • In console, no errors are generated after using innerHTML but check if any values is there or not `td.innerHTML` returns `\n\t\t\t\t\t` if no values are there. How can check if the values is there or not in my code.? – Mohemmad K Jun 27 '15 at 10:48
  • @MohemmadK Maybe can you use [`str.trim()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim), in order to remove uninteresing chars? Also, try using [`.textContent`](https://developer.mozilla.org/fr/docs/Web/API/Node/textContent) instead. – Delgan Jun 27 '15 at 10:53
  • Great answer!! Thanks for helping. – Mohemmad K Jun 27 '15 at 10:54