I am trying to print some code from PHP after clicking button in JavaScript, however the code is not running and I can't see any errors.
<script type="text/javascript src="https://code.jquery.com/jquery-
3.4.1.min.js" >
$( document ).ready(function() {
<?php echo '$("button[data-id='. $transport[0]['request']['vehicleType']
. ']" ).click();'; ?>
});
</script>
...
<script type="text/JavaScript src=" https:="" code.jquery.com="" jquery
3.4.1.min.js"="">
$( document ).ready(function() {
$("button[data-id=seated]" ).click();});
</script>
Running the code in console works just fine and the button is clicked,however echoing from php the code is present without errors but not executed and the button is not clicked.
the code is not working even like this
php
<script src="https://code.jquery.com/jquery-3.4.1.min.js" > </script>
<script type="text/javascript">
$( document ).ready(function() {
<?php echo '$("button[data-id='. $transport[0]['request']['vehicleType'] . ']" ).click();'; ?>
});
</script>
js output
<script src="https://code.jquery.com/jquery-3.4.1.min.js"> </script>
<script type="text/javascript">
$( document ).ready(function() {
$("button[data-id=seated]" ).click();});
</script>
those missing quotes and slashes came from formatting my question, im new to the forum so i wasn't sure how to format the code.
<script src="https://code.jquery.com/jquery-3.4.1.min.js" > </script>
<script type="text/javascript">
$( document ).ready(function() {
setTimeout(function(){ <?php echo '$("button[data-id='. $transport[0]['request']['vehicleType'] . ']" )[0].click()' ?> }, 100)
setTimeout(function(){ <?php echo '$("input[value='. $transport[0]['request']['vehicleSpecification'] . ']")[0].click();'; ?> }, 100)
});
</script>
A small time out and ref to element 0 was enough to make it work
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.