0

I have one text element and button element. I write 12,34,679 to text element, then press to button. It must alert() the first item of the array, generated from text element. How can I do it? Thanks!

4
  • And what have you already done? Commented Jan 19, 2014 at 16:51
  • you can use javascript for this :-) Commented Jan 19, 2014 at 16:51
  • Can you show some code? I don't follow your question. If that is a string, you can get an array out of it with myString.split(',') Commented Jan 19, 2014 at 16:51
  • Thank you very much, guys, you all! I solved the problem, with the first answer of @JaredPar! Thank you! I did it with the way, which @JaredPar said, but I think I made a problem, so it didn't work. But know it works perfect! Thanks! Commented Jan 19, 2014 at 17:01

3 Answers 3

2

Assuming that you want to create an array by splitting on commas you can do the following

var text = getTheText();
var array = text.split(',');
var first = array[0];
alert(first);
Sign up to request clarification or add additional context in comments.

2 Comments

+1 for breaking it down into understandable steps for a beginner.
Thanks, @JaredPar! You wrote first, so, I will accept your answer! ;)
1

Use the split method.

<input type="text" id="textElement">12,34,679</input>

var text = document.getElementById('textElement');
var firstIndex = text.split(',')[0];
alert(firstIndex);

Comments

1

very few informations
basically you should use split()
example:

 text = htmlElement.text();
 textArray = text.split(',');
 firstElement = textArray[0];

Comments

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.