I have a WordPress theme which uses a combination of PHP/JS/AJAX to present a booking form.
I am trying to access the value of an output field which is rendered by the following:
<div class="output">
<p><?php _e('Check-in', 'bookyourtravel') ?></p>
<p class="step_1_date_from_holder" id="pccfromdate"></p>
<p><?php if (!empty($accommodation_check_in_time)) { echo ' ' . $accommodation_check_in_time; } ?></p>
</div>
I need to get the value from the pccfromdate text. The variables that I have seen through the booking process at http://epiccloudshare.com/penninelettings/hotel/curlew-yurt-village/ are as follows:
$date_from (set up in a .js file)
$selected_date_from (seen when I do a Chrome "inspect element")
I have tried
<?php $date_from2 = document.getElementByID('pccfromdate').value; ?>
but if my understanding is starting to develop, this is not possible because PHP is server side and JS is client side
The form has a POST method against it so I also tried
<?php if(isset($_POST['selected_date_from']))
$date_from2 = $_POST['selected_date_from']; ?>
Any pointers would be appreciated
EDIT
I did not indicate that the $_POST attempt did not work either.
So, as indicated by machavity I think the answer is something to do with AJAX as the value I require is displayed via the step_1_date_from_holder class. I am able to modify the php script to assign a name and/or id to the <p> but I haven't got a clue as to how to use AJAX to get at the actual value to get it back into a PHP variable.
getElementById()and notgetElementByID()it's case-sensitive. developer.mozilla.org/en-US/docs/Web/API/Document/… and you can't inject JS into PHP like that.name="selected_date_from"input type="text",selectetc.