2

I am building a site at http://forkinthecode.net/budget/2012-2013.php

I have written a script that opens a window with a Google search url in the address bar for the Portfolios, Programs, Agencies and Objectives on each table from the MySQL database.

This script works in Chrome, Safari, IE & Opera but on my machine, when using Mozilla Firefox the variable comes up as "undefined".

I've had a look round the web and find nothing about this.

<script type="text/javascript">//<![CDATA[ 

function getPortNews() 
{   
    portfolio = document.getElementById('portfolio').innerText;
    static_url = ('http://google.com.au/search?q=');

    search_url = ( static_url + portfolio );
    window.open(search_url);

        }
        //]]></script>

I am new to JavaScript and please be aware that the site in question and the database behind it is about 75% completed.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
user1707962
  • 41
  • 1
  • 5
  • 3
    Change `innerText` to `textContent`. Or, if you really want to support old IE browsers `document.getElementById('portfolio')[document.textContent === null ? 'textContent' : 'innerText']` – Rob W Sep 29 '12 at 07:53

2 Answers2

3

Either download jQuery and use:

text() or html()

or if you stick with vanilla js, use innerHTML. It has wide support. However if getting html-tags in the result is an issue for you, you should go with Rob W's solution above, which only returns the actual texts.

Daniel Hallqvist
  • 822
  • 5
  • 15
1

There is no innerText property in the standards, which is what's biting you.

Boris Zbarsky
  • 34,758
  • 5
  • 52
  • 55
  • 1
    Thanks for the suggestions. textContext seems to work for most of the scripts. I'm still debugging the last one- objectives. – user1707962 Sep 30 '12 at 03:02
  • Got it to work on the last script by changing the variable & event handler name from Objective to Scheme. – user1707962 Sep 30 '12 at 03:19
  • @user1707962 You meant [Node.textContent](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent) not textContext – Eugen Mihailescu Sep 19 '17 at 16:34