JS Reads one value, but not another

APD Toronto
APD Toronto used Ask the Experts™
on
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?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Team Lead
Commented:
<label for="txtReservID" id="txtReservID" class="detailControls">
                    txtReservID:
                </label>
                
                <br>
                
                <input type="text" id="txtReservID" name="txtReservID" class="detailControls"
                       value="<?php echo $errand['id']; ?>">

Open in new window


These 2 elements shouldn't it be defined with different names... ?
APD TorontoSoftware Developer

Author

Commented:
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 TorontoSoftware Developer

Author

Commented:
Thank you very much!!!!
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

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.
APD TorontoSoftware Developer

Author

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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial