0

I have an input

<input type="text" value="hello" />

and I want to get the value of this and using Jquery, save the value in an array.

How can I do this???

3 Answers 3

2

using jQuery,

$(document).ready(function(){
   var arr = [];
   arr.push($('#inputID').val());
})

you should give your input an id

<input type="text" value="hello" id="inputID" />
Sign up to request clarification or add additional context in comments.

Comments

0

you could run this code for submitting:

$('formname').submit(function() {
  alert($(this).serialize());
  return false;
});

This would return a string like:

a=1

You could then save this to an array.

3 Comments

did I miss something? why are you in a form?
var arr = []; $('input:text').each(function(){ arr.push($(this).val()); });
... There are more and more people saying things like "Why are you doing that?" - Does it really matter (providing the answer is correct)?
0
var formValues = $('#your_form').serialize();
var formValuesAsArray = $('#your_form').serializeArray();

To get the value from your input, you should give it a name attribute; for example <input type="text" name="message" /> and get its value by $('input[name=message]').val()

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.