0

i have html form

<form name="updatefrm" id="updatefrm" action="" method="post">
<input type="hidden" name="98" id="98" value="" />

<input type="hidden" name="99" id="99" value="" />
<input type="hidden" name="100" id="100" value="" />
<input type="hidden" name="101" id="101" value="" />
<input type="hidden" name="102" id="102" value="" />
<input type="hidden" name="updateqty" id="updateqty" value="1" />
</form>

now i want to assign value to this elements i m using following javascript code for element with id 98

document.updatefrm."98".value = elements[0].value;

but its giving me error in console.

can any one help me with this ?

utsav
  • 1

4 Answers4

1

Why can't I have a numeric value as the ID of an element?

// Change your numeric id.

var myValue=document.getElementById('your_changed_id').value;
alert(myValue)

Go for simplicity..Instead of writing this complex code.why not try a simple code which does the same thing document.getElementById('your_changed_id').value

Community
  • 1
  • 1
HIRA THAKUR
  • 16,132
  • 14
  • 50
  • 84
1

You should use document.formname to access forms as not all browsers support this(actually I'm not sure if any does). use document.forms.formname instead. Also to access a numeric property of an object use bracket notation instead of dot notation.

document.forms['updatefrm']['98'].value = elements[0].value;
Musa
  • 93,746
  • 17
  • 112
  • 129
0

You should not give numbers as ID include any kind of character..

Try like this:

document.forms["updatefrm"]["s98"].value = elements[0].value;

Fiddle

Dhaval Marthak
  • 16,966
  • 6
  • 41
  • 68
0

You can also use getElementById to set the value. Beside this also check Javascript Naming Convention

document.getElementById('98').value = "YOUR VALUE";

Konsole
  • 3,427
  • 3
  • 27
  • 38