Reputation: 19
I am sorry if I this questions is duplication, I have read all the Q & A in the site regarding but did not find the answer.
I am getting the error message Uncaught TypeError: Cannot read property 'value' of undefined
. The funny thing is this is coming for only 1 client.
I have created a place where we can enter arrival and departure information of client but once when we are adding the one client it is coming for others it is working fine.
I have checked in all the computers in my office but still I can not add Mr. XYZ to arrival list.
This is the line
var fldQPRArrivalFlightID=document.getElementsByName('fldQPRArrivalFlightID['+fldCustomerReservationID+']['+mycount+']')[0].value;
Upvotes: 0
Views: 641
Reputation: 3849
the method getElementsByName(..)
doesnt return an array - or an empty array. Therefore, getElementsByName(..)[0]
is undefined
and you'll receive the error.
You can try logging the returnvalue of 'fldQPRArrivalFlightID['+fldCustomerReservationID+']['+mycount+']'
and verify what the invocation of getElementsByName( returnvalue )
should return.
Instead of your code:
fldQPRArrivalFlightID=document.getElementsByName('fldQPRArrivalFlightID['+fldCustomerReservationID+']['+mycount+']')[0].value;
Try
console.log( fldCustomerReservationID );
console.log( mycount );
console.log( 'fldQPRArrivalFlightID['+fldCustomerReservationID+']['+mycount+']' );
console.log( document.getElementsByName('fldQPRArrivalFlightID['+fldCustomerReservationID+']['+mycount+']') );
I'm actually surprised all this quoting goes right.
Upvotes: 1