I have a form on my website which is submitted by clicking a link. I am trying to create a custom context menu so that a user can open the submitted form in a new tab, if desired. Because the pages are generated dynamically with cgi, the parameters of the functions are different each time. I would like to trigger the function with those parameters after adding the attribute target="_blank" to the form element.
I am able to access the parameters by using document.getElementById("...").onclick and then using regexes to extract them. But this seems overcomplicated. I feel there must be a way to say, in effect, "do what you would have done if someone had left-clicked this a element". Here is some simplified code:
<a id = "link" style = "cursor:pointer" onclick = "postform('1')">link</a>
<FORM id = "remote"><input id = "input" type = "hidden" name = "firstkey" value = ""></FORM>
I have the JS in a separate file, it basically says:
function postform(valueone) {
document.getElementById("input").value = valueone;
document.getElementById("remote").submit();
}
what I have now for opening in a new tab is:
function contextmenu() {
var parameters =document.getElementById("newtab").onclick;
//regexes go here
postform(parameters);
}
What I am asking is, is there a way in a line or two to replace what I am doing inside the contextmenu function which would fire the onclick event attached to the link with its parameters?
thisand then pass it in for a reference to what was clickedthis.onclickfor example, I would be in the same position I described in the question.