javascript/ php/ jquery

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.

Related Question JQuery not running from PHP echo PHP convert javascript when echo Running javascript inside php without echo Echo PHP variable from JavaScript? echo javascript from php not working? Echo a value from php to javascript Javascript not working when echo'd by php Javascript code not functioning with PHP when echo'ed Calling a javascript function from a php echo make a Javascript array from php echo output
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM