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.

4
  • 2
    What browser is that? The indexOf() method is not supported in Internet Explorer 8 and earlier. Commented Jan 22, 2013 at 13:56
  • 1
    What browser are you testing this in? Array.indexOf() is a fairly recent addition to ECMAScript. Commented Jan 22, 2013 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? Commented Jan 22, 2013 at 14:04
  • 1
    related thread "How to fix Array indexOf() in JavaScript for IE browsers" - stackoverflow.com/questions/1744310/… Commented Jan 22, 2013 at 14:22

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.