Placing Javascript within the Page HTML

This section is for posting questions which are not directly related to WYSIWYG Web Builder.
Examples of off topics: web server configuration, hosting, programming related questions, third party scripts.

Note that these questions will generally not be answered by the administrators of this forum.
Post Reply
GeraintR
 
 
Posts: 14
Joined: Thu Jan 09, 2025 4:29 pm
Location: Manchester

Placing Javascript within the Page HTML

Post by GeraintR »

I need to identify the selected row of a datatable or dropdown, and store it as session data to be used in another page. I have been working through a Javascript tutorial to develop my very basic JS skills, and have even failed to get a JS script to change an HTML heading because I cannot place the <script> tag at the appropriate place within the generated HTML <body>. Is there any way of placing it correctly other than the options available within the page HTML? I don't want to edit the page externally because it will be changed regularly over the next few weeks.
User avatar
BaconFries
 
 
Posts: 5946
Joined: Thu Aug 16, 2007 7:32 pm

Re: Placing Javascript within the Page HTML

Post by BaconFries »

Moved to Off Topic Section. You can add scripts such as javascript by using the "Page HTML" as shown at the following or by using the HTML Object itself. HTML Object If the script is in the form of an external file you can then use the "File Publisher Object" and then reference it in the HTML by using the already mentioned "Page HTML". Please note that the software is not a HTML Editor but a HTML Generator what this means is that the HTML doesn't exist till you publish it. The only downside of adding externally is when you make the changes and then open the page again in the software it will not be saved and you will need to add again.
User avatar
Pablo
 
Posts: 23469
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Placing Javascript within the Page HTML

Post by Pablo »

If the code does not work then there is most likely an error or conflict in the script you have added.

More details about placing code is available here:
https://www.wysiwygwebbuilder.com/add_html.html
GeraintR
 
 
Posts: 14
Joined: Thu Jan 09, 2025 4:29 pm
Location: Manchester

Re: Placing Javascript within the Page HTML

Post by GeraintR »

Thank you both for your prompt replies. I see on the advice page about code placement says that scripts should not be put within the body tag. The W3schools tutorial that I've been using does just that, putting a function within the body tag, which was what I was originally trying to do. I shall remain confused, hopefully temporarily! Using an external file is probably the best option. The test code I was using to ascertain where it should be placed was very simple: <script> document.getElementById("wb_Heading1").innerHTML = "<h1>Swift locations</h1>";
</script>

I suspect the problem was that I couldn't place it after the element it was referencing. Anyway, I appreciate that this is not a forum for coding issues, but I felt that the page HTML options just about justified me asking the question. I think that I have a Heath Robinson solution that I can implement whilst I develop my Javascript knowledge. I'll get users to submit a form into a dustbin database table, and use the Session or Webstorage function to store the foreign key that I need to populate a field on a different page. The surveys for which I created the database will start in June and I don't want to input the data myself.
User avatar
Pablo
 
Posts: 23469
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Placing Javascript within the Page HTML

Post by Pablo »

The code you are referring to cannot be placed between the head tags, because you will have to wait for the page to finish loading before you can access the element.
So, either add the code at the end of the page or use a DOMContentLoaded event.
This is not related to the software but how HTML works,.
Post Reply