0

forexample, i have this code:

<input type="text" name="width[]">
<input type="text" name="width[]">
<input type="text" name="width[]">
<input type="text" name="width[]">
<input type="text" name="width[]">
<input type="text" name="width[]">

How can I read this value by javascript array. I could do that using php like this;

<?
    $values=$_POST['width'];
    foreach($values as $value){//each value}
?>

the javascript variable's each value should be accessible using loop.

0

3 Answers 3

1
document.getElementsByName('width[]');
Sign up to request clarification or add additional context in comments.

Comments

1

As you said you use Jquery ..here's the Jquery method

$(document).ready(function(){
  $('input[name="width[]"]').each(function(){
      alert($(this).val());
  });

});

Comments

0
var myForm = document.forms.id_of_form; 
var myControls = myForm.elements['width[]']; 
for (var i = 0; i < myControls.length; i++) { 
    var aControl = myControls[i]; 
}

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.