Add remove SAP HTML buttons or links using javascript

Adding and removing HTML elements such as buttons and A href links dynamically is very simple using javascript. If you are bored of reading already feel free to go straight to the end of this article where there is a

Below is the individual JavScript code for implementing the various methods of doing this either by showing/hiding and element on screen or by removing it altogether and then re-adding it. Both have there pros and cons so just need to decide which fits in with your requirements.


Full code listing
Alternatively here a basic code snippet which you can just copy and paste into your your SAP BSP or a HTML file and test this out for yourself.



<title>Demonstrate how to add and delete buttons and links</title>

<script type=”text/javascript”>
function delbutton()

var elem = document.getElementById(‘report1’);


function addbutton()

var addbut = document.createElement(‘input’);
addbut.type  = “submit”;
addbut.value = “Test Button”; = “test1”; = “report1”;
addbut.setAttribute(‘class’, ‘test’);

function dellink()

var elem = document.getElementById(‘report2’);


function addlink()
var addLink = document.createElement(‘a’);
var linkText = document.createTextNode(“Test link”);
addLink.title = “title”;
addLink.href = “#”; = “report2″;
addLink.setAttribute(‘class’, ‘test’);


function hideelement() {

document.getElementById(‘report1’).style.visibility = ‘hidden’;

function showelement() {

document.getElementById(‘report1’).style.visibility = ‘visible’;



<form id=”sapbspform” name=”sapbspform” method=”post” action=””>

<li id=”button1″>
some text
<input id=”report1″ type=”submit” name=”testbut1″ value=”Test Button” >
some more text

<li id=”link1″>
<a  href=”#” id=”report2″ value=”1″  >Test link</a>
<a  href=”#” onclick=”delbutton();” value=”Del” id=”delbutton” >del button</a>
<br><a  href=”#” onclick=”addbutton();” value=”Add” id=”addbutton” >Add button</a>

<br><br><a  href=”#” onclick=”dellink();” value=”Del” id=”dellink” >del link</a>
<br><a  href=”#” onclick=”addlink();” value=”Add” id=”addlink” >Add link</a>

<br><br><a  href=”#” onclick=”hideelement();” value=”Del”>Hide button</a>
<br><a  href=”#” onclick=”showelement();” value=”Add”>Show button</a>


Executing the HTML code
When you execute the report you will notice the following behaviour:

  • Clicking the Del button
    Notice that when the button is deleted the text either side closes together and uses the space where the button used to be. Also note this means that once it has been removed you can no longer reference the element within your JavaScript.


  • Clicking the Hide button
    When the button is hidden its still takes up the same space but




Leave a Comment: