0

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.

cjbarth
  • 4,189
  • 6
  • 43
  • 62

2 Answers2

2

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.

Ruan Mendes
  • 90,375
  • 31
  • 153
  • 217
  • Nice, it answers the question and I laughed. – Hemlock Dec 28 '10 at 19:01
  • Wow, that directly answers how to programmatically click. Silly me. Thanks. – cjbarth Dec 28 '10 at 19:32
  • I was testing this and found that it doesn't work as expected. Since the button posts the page is refreshed and then the onload event with the .click() event is fired again. Any thoughts on where else to put this call so it doesn't get called more than once? – cjbarth Dec 30 '10 at 18:38
  • It seems it's one of those pages that submit to themselves, how I hate those. Add a url parameter to the submit that you can detect onload so you don't reclick it every time. Nasty hack, but if you don't want to fix the mess you have, you have to do something like that! – Ruan Mendes Jan 03 '11 at 03:50
  • I think I understand what you are saying: modify the action of the form, right? However, there are three buttons on the form that all submit to themselves (OnBase engineering at work here). How might I specify which button was clicked? Do you have a simple example? – cjbarth Jan 06 '11 at 20:50
  • I have no idea what OnBase Engineering is. As I understand your problem, you are calling `click()` from onload. You just need to set some variable on the server when handling that button's submit, so that the next time it loads, it doesn't call click. For further help, show some code (removing the irrelevant parts) and explain which part is broken, how it's broken and what you'd expect it to do. – Ruan Mendes Jan 06 '11 at 21:46
  • When I say 'OnBase engineering' I was referring to the way they designed their product. I have no way to handle anything on the server; OnBase wrote all that code and I can't interact with it at all. I just want to open a child window `onload` which OnBase specified I do by posting from a specifically named button. I don't want this to happen every time the page posts back, just on first load. – cjbarth Jan 17 '11 at 19:15
0

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.

John Koerner
  • 37,428
  • 8
  • 84
  • 134