Link to home
Start Free TrialLog in
Avatar of APD Toronto
APD TorontoFlag 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?
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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

Thank you very much!!!!
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
Sorry, looks like you beat me to it.
Thank you both, I was working on that module for 12 straight hours and just got tired.