NetTalk Central

Author Topic: Save Form Automatically  (Read 3006 times)

gavinwebb

  • Newbie
  • *
  • Posts: 40
    • View Profile
    • Email
Save Form Automatically
« on: February 13, 2012, 04:52:46 AM »
I know there is a post from a few years ago similar to this but I don't quite understand it and I wonder if there is now a different\better way to do it.

Basically I open a Form from a Browse, on the Form I'm using the auto-lookup (now that it's working again).  Once the user returns from the lookup I want to save the form straight away.  It seems I need to put some javascript in to do this, but I don't know where or how - have seen this:

<script type="text/javascript">
document.getElementById('save_btn').click()
</script>

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Save Form Automatically
« Reply #1 on: February 13, 2012, 11:32:12 PM »
In NetTalk 6 that code probably won't work because the ID of Save buttons has changed. Because a screen can contain multiple Save buttons it's a lot harder to specify which button you'd actually want to press.

On the up side, the inclusion of jQuery makes it a lot easier to select the button, so that's something.

In terms of where to put this, I'd say, since you want to do it after a lookup, I'd put it in the AfterLookup routine.

In terms of what to put, I think something like this might work;

    p_web.Script('jQuery(''#updatemailboxes_div [name="save_btn"]'').click();')

while a complete discussion of jQuery "Selectors" is outside the scope of this reply, suffice to say, you are looking for an element, inside the "element with ID= updatemailboxes_div" with the "name" attribute set to "save_btn".
And then clicking it.

the p_web.Script method is a good way to inject scripts into a reply, because all the hard work of managing context is done for you.

Two things to note,
1) be careful spotting the difference between two single quotes, and one double quote in the above example.
2) the name of the procedure must be "lowered" - ie I've used updatemailboxes in this example, even though the procedure name is UpdateMailBoxes. also notice the _div tacked on to the end of the procedure name.

Cheers
Bruce



 

gavinwebb

  • Newbie
  • *
  • Posts: 40
    • View Profile
    • Email
Re: Save Form Automatically
« Reply #2 on: February 17, 2012, 10:29:08 AM »
Worked great - thanks Bruce, put at end of AfterLookup routine, just needed to figure the _div name, but that was was using "inspect element" in Chrome.

Cool, my first bit of javascript!

G