dimanche 3 juillet 2016

Get textbox value in single/multiple

I have a field in my page named as "myField" Now this is dynamic So there are 2 cases i.e. it can be just 1 field as;

<input type="text" name="myField" />

OR there can be 2 fields as below;

<input type="text" name="myField" />
<input type="hidden" name="myField" />

I use the following code to access the value in JS;

document.forms[0].myField[0].value

However, this does not work if there is only 1 field (as in the first case)

How do I write dynamic JS code to handle the same? It should be cross browser compatible.

Aucun commentaire:

Enregistrer un commentaire