I have little problem with JS so Hope it will be solved here There is two input type in one form like <input type="checkbox" name="test" value="123"> <input type="hidden" name="test" value="456"> and I want to have Value of Both type true javascript I did javascript:alert(document.getElementsByName['test'].value); but nothing happen, What should I write to get value of both types.
Why do they need the same name? You can't work with it this way. If you submit the form, how do you know later on the server which is which? You can make an HTML array and send both, like this: <input type="checkbox" name="test[]" value="123"> <input type="hidden" name="test[]" value="456"> HTML: But anyway, getElementsByName is a function, and therefor it should have parenthesis instead of brackets. Also, it will return an array with the 2 fields, so you have to specify which you want to alert(). alert(document.getElementsByName('test')[0].value); Code (javascript): This should work.
<input type="checkbox" name="test[]" value="123"> <input type="hidden" name="test[]" value="456"> HTML: Actually I am not going to create this form but it is readymade on One web page, I want to get data of that page true JS, That was the format of form which I posted in the thread.
Then you can take out the brackets, and the line I posted above should work: alert(document.getElementsByName('test')[0].value); // And alert(document.getElementsByName('test')[1].value); Code (javascript):