It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

I was testing out HTML Macro, enabled by our admin, by using a very simple page, including a simple JScript. The HTML was running fine if directly loaded into browser (I use Chrome), however it doesn't work if included as part of confluence page.  The code is like this, and "action="javascript:handleIt()"" is not calling the function "handleit" at all when this code is part of confluence page.  Please help me understand.  Thanks.

<!DOCTYPE html>
<html>
<head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}

td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}

tr:nth-child(even) {
background-color: #dddddd;
}
</style>
<script type="text/javascript">

function handleIt() {
alert("hello");
}

</script>
</head>


<body>
<form name="CandidateTable" action="javascript:handleIt()">
First name:<input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input name="Submit" type="submit" value="Add Candidate"/>
</form>
</body>

</html>

2 answers

1 accepted

0 votes
Answer accepted
Davin Studer Community Leader Aug 10, 2016

In the html macro just do something like this. Don't add the html, head, or body elements ... that is invalid html. You cannot nest a html DOM tree within a body element.

&lt;style type="text/css"&gt;
table {
	font-family: arial, sans-serif;
	border-collapse: collapse;
	width: 100%;
}
td, th {
	border: 1px solid #dddddd;
	text-align: left;
	padding: 8px;
}
tr:nth-child(even) {
	background-color: #dddddd;
}
&lt;/style&gt;
&lt;script type="text/javascript"&gt;
function handleIt() {
	alert("hello");
}
&lt;/script&gt;
&lt;form name="CandidateTable" action="javascript:handleIt()"&gt;
	First name:&lt;input type="text" name="fname"&gt;&lt;br&gt;
	Last name: &lt;input type="text" name="lname"&gt;&lt;br&gt;
	&lt;input name="Submit" type="submit" value="Add Candidate"/&gt;
&lt;/form&gt;

You would need to save the data elsewhere though. The above html will not save it to Confluence. You could achieve this through AJAX calls to a web service (that you create). I think a better method if you want to do it all in Confluence would be to check out ConfiForms. You can create forms like that (without programming) and store the data. You can do CRUD (create, update, delete) operations on the data and all sort of reporting. It's not free, but it is surprisingly well priced for all the slew of things it can do.

0 votes

It's too late for javascript to execute in the body of a macro - the <head> section of your code is effectively ignored because the <head> of the page has already been completed before the body of the page starts.

Thank you, @Nic Brough [Adaptavist], for your answer.  Would you kindly share how it should be modified?  I saw on the answer to another post that <html> <head> and <body> should not be used in html macro, so I deleted those tags, and still same thing that the JScript is not getting executed as the form action.

 

My final goal is to have a page where someone can enter information (thru a form), keep those information saved on server, and have a checkbox for each item to indicate if any of them is claimed by anyone (like a simple check-in/check-out system).  Is there a way to achieve this goal, all within a confluence page?

 

Thank you very much!

As I said, your javascript won't run.  The point is that your scripts need to be placed in the structure of the page, not as part of the content.

Confluence is not a checking system or for doing "forms", it's a wiki-like documentation system.  You might find some add-ons in the marketplace to help you, but I'd be looking at something that has a proper process flow, like JIRA

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Confluence

What's New in Confluence Cloud – November 2019 Edition

Hey community! This month we’re excited to share brand new features to help you make your mark on Confluence. If you haven’t already, check out our updates from October and September too! Expre...

32,469 views 29 60
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you