Web Analytics Made Easy -
StatCounter String to Array Question - CodingForum


No announcement yet.

String to Array Question

  • Filter
  • Time
  • Show
Clear All
new posts

  • String to Array Question

    Good morning all! I have a quick question and would appreciate any help.

    I want to pass an array from my html page into a function. The trick is my array is actually entered as a comma separated string.

    This is what I was thinking:

    I want to enter the array as as string in a text box, then using a button call my getarray function, which pulls the comma separated text from the text field and converts it to an array. While within this function, I'd like to call a function to do things with the array. This is not working,

    Is this the most efficient (read, easiest for a beginner) way to do this? Or, is what I'm wanting to do impossible?

    I would appreciate any advice.


    function getarray(){
    var origarray = document.getElementById("enterarray"); //enter array is the textbox on the html page
    var array = arrayorig.split(','); //splits the string at the ",'s
    function doSomething(array); //performs an act on the array

  • #2
    You are trying to split the element- you need the element's value.
    (You also changed the name in the middle of the function from origarray to arrayorig)
    Hopefully, enterarray is an id and not a name here:
    var array = document.getElementById("enterarray").value.split(',')