I'm having problem with the following code. It is supposed to create a specified number of page links that i will go onto get to sort search results into different "pages" (i'm actually just gonna be changing the innerHTML element) which can be individually be accessed by each individual links, ie. Page 1 link accesses content of search result page 1
The code is:

<script language="javascript">

//idP is the id of the P tag
//jsCode is the javascript function that i want the link to run
//linkTxt is the text displayed of the link

function newLink(idP, jsCode, linkTxt) {
alert("running ...");
document.getElementById(idP).innerHTML += "<a href='javascript:" + jsCode + "'>" + linkTxt +"</a> &nbsp;";

//idP is the id of the P tag
//commonName is something like "Page" so every link will be named "Page" + their number.
//num is the number of links required

function loopLinks(idP, num, commonName) {
var i = 0;
while (i < num) {

// ERROR: "alert();" of the following, tries to link to "javascript:alert();" but if you attempt to put
//something in, like "alert('hi');" it tries to link to "javascript:alert(" and ignores the rest

newLink(idP, "alert();", commonName + (i + 1));

<input type="button" value="Go" onclick="loopLinks(htmlArea.id, 3 , 'Page');">
<p id="htmlArea">

Any help would be very much appreciated