Avatar of APD Toronto
APD Toronto
Flag for Canada asked on

JS Reads one value, but not another

Hi Experts,

I have 2 textboxes as follows
            <div class="divDetailDivs">
                
                <label for="txtPickupDate" id="lblPickupDate" class="required detailControls">
                    Pickup Date:
                </label>
                
                <br>
                
                <input type="text" id="txtPickupDate" name="txtPickupDate" class="required detailControls"
                       maxlength="10" value="<?php echo $errand['pickup_date']; ?>">
                
            </div>

            <div class="divDetailDivs">
                
                <label for="txtReservID" id="txtReservID" class="detailControls">
                    txtReservID:
                </label>
                
                <br>
                
                <input type="text" id="txtReservID" name="txtReservID" class="detailControls"
                       value="<?php echo $errand['id']; ?>">
                
            </div>    
        

Open in new window


When I try to read the value from the first it works, but it does not in the second
var conf = document.getElementById('txtPickupDate').value; //Returns a value
var conf = document.getElementById('txtReservID').value; //Returns 'Undefined'

Open in new window


I do not get any errors.

Can anyone see why this is happening?
JavaScriptHTML

Avatar of undefined
Last Comment
APD Toronto

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Ryan Chong

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
APD Toronto

ASKER
The resulting HTML is
<input id="txtPickupDate" name="txtPickupDate" class="required detailControls" maxlength="10" value="2014-06-09" type="text">

<input id="txtReservID" name="txtReservID" class="detailControls" value="75768" type="text">

Open in new window

APD Toronto

ASKER
Thank you very much!!!!
bigeven2002

Hello,

In your HTML, on line 16 for the Label tag, the ID is the same as the input tag.  So change your label tag ID to lblReservID
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
bigeven2002

Sorry, looks like you beat me to it.
APD Toronto

ASKER
Thank you both, I was working on that module for 12 straight hours and just got tired.