2

i using hidden's input

<input type='hidden' name='bahan' id='bahan' />

then, i want pass a value from js. i have a function called resultBtn() i get the value from it, example string var x='12,124'; i want take the value from other input

<?php $i=0; foreach ($bahanx as $pin2){ 
  echo "<div class='input-group' style='width:175%'><label class='input-group-addon' style='width:100px'><input type='checkbox' name='bahan' aria-label='Checkbox for following text input' value='".$pin2->id_barang."' oninput='changeText(this,".$i.");' > ". $pin2->nama_barang ."</label><input type='text' class='form-control' aria-label='Text input with checkbox' name='banyak_bahan' value='0' disabled/></div><br/>";
  $i++;  }  ?>

at resultBtn() i make a formula from bahanx then the result is x variable. this is my js

document.getElementsByName('bahan').value=x;
2
  • 1
    document.getElementsByName('bahan')[0].value=x; Commented Oct 24, 2016 at 6:29
  • ty bro, it worked Commented Oct 24, 2016 at 6:33

1 Answer 1

1

The getElementsByName method returns a collection of elements(NodeList) so you need to retrieve element by index.

document.getElementsByName('bahan')[0].value = x;
//                           ------^^^------
Sign up to request clarification or add additional context in comments.

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.