4

I am writing a program that takes all of the text from a text box, parses it into an array removing white-space, and then will search the array for expected values.

I can test it and get the program to successfully take the text in the text box and parse it into the array, but when I try to find the expected values in the array, it throws an error. The error is, "Object doesn't support this property or method".

JavaScript:

function generateOutputfvoc()
{
    var inputArr = document.getElementById("inputBox").value.split(/[\s]/);
    var nameLoc = inputArr.indexOf("Name");
    document.getElementById("contactNameOutput").innerHTML = nameLoc;
}

HTML snippet:

<p>Paste Text Here</p>
<textarea rows='8' cols='152' id='inputBox' placeholder="Copy text and paste here" wrap="off"></textarea>
<form><input type='button' onclick='generateOutputfvoc()' value='Generate Output' /></form>
<p>Contact Name: <b id='contactNameOutput'></b></p>

Thank you.

Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
Mrow
  • 115
  • 2
  • 10
  • 2
    What browser is that? The indexOf() method is not supported in Internet Explorer 8 and earlier. – Thilo Jan 22 '13 at 13:56
  • 1
    [What browser](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/indexOf#Browser_compatibility) are you testing this in? `Array.indexOf()` is a fairly recent addition to ECMAScript. – Mattias Buelens Jan 22 '13 at 13:57
  • I am testing it in IE8. I tried it in FF and it worked. Thank you for the prompt replies. I am concerned because I am going to need this to work with all versions of IE. Any ideas on backwards compatibility? – Mrow Jan 22 '13 at 14:04
  • 1
    related thread "How to fix Array indexOf() in JavaScript for IE browsers" - http://stackoverflow.com/questions/1744310/how-to-fix-array-indexof-in-javascript-for-ie-browsers – benbai123 Jan 22 '13 at 14:22

1 Answers1

3

You can add indexOf() utilizing the prototype feature of javascript according to this page: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/indexOf

javabeangrinder
  • 6,939
  • 6
  • 35
  • 38
  • Thank you. I am using IE8 to test the code, which seems to be the problem. I put the compatibility code into my program and it works! I have a new concern however... I get the correct value when I run the program in IE8 now, but in FF I get a different value when using the same text. Any ideas? – Mrow Jan 22 '13 at 14:16