Forum Moderators: open

Message Too Old, No Replies

php echo inside jquery

         

greencode

5:52 pm on Nov 15, 2016 (gmt 0)

10+ Year Member Top Contributors Of The Month



I'm sure this is really simple and I'm being really stupid but I can't get this to work…


<script type="text/javascript">
$( "#simplemap" ).after( "<?php
$page_intro = get_field('page_intro');
echo $page_intro; ?>
" );
</script>


However in the code it comes out like this:

$( "#simplemap" ).after( "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut at sollicitudin leo. Aenean ac tortor eu est ultricies posuere quis at velit. Nam blandit sed purus quis vehicula. Aliquam id dolor quis odio ultrices convallis. Praesent sit amet libero vestibulum, luctus nunc sit amet, congue leo. Mauris vitae nunc quam. Mauris euismod elementum ultrices.</p>


i.e. it appears to be missing the end

" );


Any ideas or help would be much appreciated.

topr8

12:45 pm on Nov 16, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



just a weird thought ... there isn't a ton of whitespace after the text in the db field is there?

greencode

12:51 pm on Nov 16, 2016 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi. No, no space at all. Tried the same with just a word and it still doesn't include the end tags of… ");

topr8

4:04 pm on Nov 16, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



that was just my wild thought.

is the rest of the code being written, eg. the closing script tag and the rest of the page.
or does it just truncate at that point.

greencode

4:10 pm on Nov 16, 2016 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi. Yep, everything else is being written. The only bit missing is the "); and therefore it doesn't display on the page.

LifeinAsia

6:06 pm on Nov 16, 2016 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Just for fun, have you tried the following?
<script type="text/javascript">
$( "#simplemap" ).after( "<?php
$page_intro = get_field('page_intro');
echo $page_intro; ?>" );
</script>

greencode

6:59 pm on Nov 16, 2016 (gmt 0)

10+ Year Member Top Contributors Of The Month



I can see what the problem is but no idea how to resolve. Basically when it's getting that field it's then pushing the closing

");</script>


Onto the next line which is why it's causing the error and not displaying?!

<script type="text/javascript">$( "#simplemap" ).after( "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut at sollicitudin leo. Aenean ac tortor eu est ultricies posuere quis at velit. Nam blandit sed purus quis vehicula. Aliquam id dolor quis odio ultrices convallis. Praesent sit amet libero vestibulum, luctus nunc sit amet, congue leo. Mauris vitae nunc quam. Mauris euismod elementum ultrices.</p>
");</script>

topr8

8:02 pm on Nov 16, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



how about doing something mad like

<script type="text/javascript">
$( "#simplemap" ).after( "<?php echo get_field('page_intro'); ?>" );
</script>