Problem trying to populate a section's innerHTML

  • baileynp
  • Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 76
  • Thank you received: 1

baileynp created the topic: Problem trying to populate a section's innerHTML

Hi

I'm currently working on my Thank You page, and can successfully output data using the form's 'After' piece with the code below:
// Build the HTML string
	$str_html = "";
	$str_html .= "<br><h4>Thank you for completing your Placement Test.</h4><br>";
	$str_html .= "<p style='font-size: 115%;'>You answered " .$pt_score. " out of 50 questions correctly.</p>";
	$str_html .= "<p style='font-size: 115%;'>You are ready for: <strong>" .$ss_level. "</strong> level. At this level:</p>";
	$str_html .= "<ul style='font-size: 115%; list-style-type: disc;'>";
	for ($i = 0; $i < count($cefr_can_do_current); $i++) {
		$str_html .= "<li>" .$cefr_can_do_current[$i]. "</li>";
	} // for
	$str_html .= "</ul>";

	echo $str_html;

However, I want to 'wrap' this data in a section using:
echo "<script type='text/javascript'>document.getElementById('section_pt_results').innerHTML = " .$str_html. "; </script>";

but this doesn't do anything. :(

Any idea why this doesn't work?

Regards
#237488
  • Posts: 2553
  • Karma: 87
  • Thank you received: 343

mihaela replied the topic: Problem trying to populate a section's innerHTML

Hello,

Just to be sure, you are not using the standard way of creating the "Thank You Page" because you wish to display values submitted in the form, in that page, am I right?

If that is the case, great that could you please send me your backend login info to mihaela.kobovac@crosstec.org so I can take a look at your form from the first hand and try to make this as you want?

On your Thank you page, is the section with the ID "section_pt_results" present?

Regards,

Mihaela
#237491
  • baileynp
  • Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 76
  • Thank you received: 1

baileynp replied the topic: Problem trying to populate a section's innerHTML

Hi :)

In answer to all your questions: yes. :)

The login details are:

This message contains confidential information


The form is Student Placement, and the After Form piece can be found as a separate library 'piece' named ff_StudentPlacementAfterPiece.

The last page (5) has a section named 'section_pt_results'.

From the frontend, the form can be found here , but to get to the final page, I'm afraid you'll have to test your English skills, ;) but you can enter any details you want. :)

Regards
#237492
  • baileynp
  • Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 76
  • Thank you received: 1

baileynp replied the topic: Problem trying to populate a section's innerHTML

Hi Mihaela

I've just noticed that an error message is generated when trying to populate the section using
echo "<script type='text/javascript'>document.getElementById('section_pt_results').innerHTML = '" .$str_html. "'; </script>";
.

The error is
Unexpected token '<'
, which is not exactly very informative, but it does suggest that the error is generated when the parser is trying to evaluate the string.

I'm still stuck though. :(
#237510
  • baileynp
  • Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 76
  • Thank you received: 1

baileynp replied the topic: Problem trying to populate a section's innerHTML

Apologies - I just noticed you're logged in and I had to do a restore from last night.

I'll leave it alone from now on.
#237516
  • Posts: 2553
  • Karma: 87
  • Thank you received: 343

mihaela replied the topic: Problem trying to populate a section's innerHTML

Hello again,

I've been trying to resolve the issue, but didn't manage to do so.

Here is what I did so far.
In the section "section_pt_results" in your form I've clicked on Description > Edit and in the code tab I've added the following:
<div id="mytestdiv"></div>

Then, at the end of the code in the ff_StudentPlacementAfterPiece piece I've added the following:
echo '<script type="text/javascript">
<!--
document.getElementById("mytestdiv").innerHTML = \'<div>'.TESTING.'</div>\';
//->
</script>';

That is displaying the text "TESTING" in the wanted "section_pt_results" section, but didn't manage to get the variable $str_html to print out there.

Despite that, I did manage to display for example, $pt_score retrieved from the form result like this:
       echo '<script type="text/javascript">
<!--
document.getElementById("mytestdiv").innerHTML = \'<div>'.$pt_score.'</div>\';
//->
</script>';

This is a step forward in achieving what you want. It might help you to get the wanted result.
Let me know whether you've managed to do more with this code.

If not, it might be a good idea to put the whole "Build the HTML" code in the Edit section and just leave out span-s to be filled in with values. Then you would fill them in with statements like:
       echo '<script type="text/javascript">
<!--
document.getElementById("span1").innerHTML = \'<div>'.$pt_score.'</div>\';
document.getElementById("span2").innerHTML = \'<div>'.$ss_level.'</div>\';
//->
</script>';
I hope that you understand what I'm trying to explain.

Regards,

Mihaela
#237517
Moderators: ForumSupporttomeperica
Time to create page: 0.067 seconds

New Icon Packs Category!

Crosstec is now offering icon packs.

If you are a paying subscriber, icon packs are automatically added to your account.

Check out our icon packs page!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Summer Sale!

50% discount on all of our extension subscription plans, templates and icon packs!

Get Your Subscription Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99 for just 49! (Summer Sale)

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here