To open no of new tabs in browser , We have to dynamically create forms on fly on any particular event like page load, on click etc.
//helper function to create the form
function getNewSubmitForm(val){
var submitForm = document.createElement("FORM");
document.body.appendChild(submitForm);
submitForm.method = "POST";
submitForm.target ="_BLANK";
submitForm.name ="frm";
submitForm.id = val;
return submitForm;
}
Above function create form element and its set its attributes.
//helper function to add elements to the form
function createNewFormElement(inputForm, elementName, elementValue){
//Create an input type dynamically.
var element = document.createElement("input");
//Assign different attributes to the element.
element.setAttribute("type", "hidden");
element.setAttribute("value", elementValue);
element.setAttribute("name", elementName);
inputForm.appendChild(element);
return element;
}
This function set the hidden fields and value of form elements.
//function that creates the form, adds some elements
//and then submits it
function createFormAndSubmit(val){
var submitForm = getNewSubmitForm(val);
createNewFormElement(submitForm, "act", "checkurl");
createNewFormElement(submitForm, "websiteId", val);
submitForm.action= "test-url.php";
submitForm.submit();
return false;
}
Above function create form element and submit form.
function start(start,end){
for(var i=start;i<=end;i++){
alert(i);
createFormAndSubmit(i);
}
}
By giving start and end limit , we can create no of forms as per our requirements.
We can you above function using this single function,it will invoke other functions automatically :
onclick="start(1,10)"