JavaScript auto-POST with NAME

2019-09-09 12:50发布

I have an OnBase e-Form that I'm building. There are three buttons on the form that all submit. OnBase does different things based on the name of the button used to submit the form. If the button has a name of OBBtn_CrossReference it opens another window with a cross referenced document. I need to programmatically 'click' that button.

I've read several posts about how to use JavaScript to submit a form, but none seem to accomplish my goal. I just need to POST and to have it appear to come from a button named OBBtn_CrossReference.

I don't need to submit any data. The way the page is currently set up, the entire page is already a form and since I don't want to break the functionality of the other form buttons it seems I must leave it that way.

UPDATE: The suggestion below was tested as a call from the onload event in the body tag and since the button posts the page reloads and the call is made over and over again spawning unlimited child windows. I would appreciate a suggestion on how to get the button to only be clicked the first time the page is loaded and not on postback.

2条回答
2楼-- · 2019-09-09 13:06

I know I am a little late to this post, but you can try and leverage a cookie to get this done:

if (document.cookie.indexOf('xref=true', 0) < 0) {

    // Set the xRef cookie, so we do not fire it again for this form.
    document.cookie = 'xref=true';

    //alert(document.cookie);
    document.getElementById("OBBtn_CrossReference").click();
}
else {

    document.cookie = "xref=false";
    //alert(document.cookie);
}

I tested this on the Thick and Thin clients in 10.0 and it worked fine.

The postings on this site are my own and don't necessarily represent my company's positions, strategies or opinions.

查看更多
一纸荒年 Trace。
3楼-- · 2019-09-09 13:15

There's a click() method on links, buttons, checkboxes. For example , I submitted this comment by running document.getElementById('submit-button').click() from chrome's command line.

查看更多
登录 后发表回答