0

Simple question but I can't find a direct answer. Suppose I have two input fields:

<input type='hidden' id='cat' />
<input type='hidden' id='dog' />

How can I assign each a different value from Javascript? I know how to do this with one value:

<input type='hidden' id='cat' />

<script type="text/javascript">
document.getElementById('cat').value='meow' ;
</script>

But can't seem to make this happen with two different values.

3
  • 2
    how are you trying to do two? Your sample for doing it with one is straight forward and works fine Commented Sep 26, 2013 at 15:14
  • 2
    adding document.getElementById('dog').value='woof' ; to your javascript code doesn't work? Commented Sep 26, 2013 at 15:15
  • You will have to loop through each hidden fields if those all are of the same type and then you can assign values one by one. But this sort of practice would make any sense.. :) Commented Sep 26, 2013 at 15:16

1 Answer 1

1
<input type='hidden' id='cat' />
<input type='hidden' id='dog' />
<script type="text/javascript">
document.getElementById('cat').value='meow';
document.getElementById('dog').value='woof';
</script>
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.