Submit button using code

I would like to use code to support a button that submits data entered in an input box into a database collection.

I know this can be done without using code, but I want the button to perform other fuctions simultaneously so I think I need to use code.

Help would be muchly appeciated… Thanks

Hi,

there are two ways to go about it.

  1. Add a regular button and use onClick event handler.

From there you can submit the form bound to a dataset using

$('#dataset1').save()

(replace #dataset1 with actual ID of your dataset)

You can add vent handlers by clicking + as depicted in the illustration.

  1. Submit the form using regular button bound to save action and perform additional actions when form is submitted in onAfterSave handler on a DataSet.

When trying to use $w(‘#dataset1’).save(); I get an error message saying ““save” is undefined”.
Here is more information on what I am trying to do…

I want users to type an answer in input box “2q1”.
Then when the user presses the submit button next to that answer, I want the following to happen;

  1. the answer to save into the database that is dynamically connected to this page (Players) into the cell that is linked to the input box “2q1”.
  2. the input box to collapse
  3. the submit button to collapse
  4. the textbox “2a1” to expand
  5. the textbox “2a1” to show the user the answer that they just typed in


So far, I have been able to points 2, 3 and 4 using the following code…
export function Submit2q1_click() {
$w(“#2q1”).collapse();
$w(“#2a1”).expand();
$w(“#Submit2q1”).collapse();
}

I tried adding the line $w(“#2q1”).save(); but this did not work. I am probably using .save() wrong.
Hope you can help, thanks!

An additional note:
You will notice that there are multiple submit buttons.
When each submit button is pressed I only want it to perform the above actions for the input box next to it, each is linked to a different cell in the datacollection “Players”.

SOLVED!

Can be done without code, each input field needs to be set to “not required”, then it allows you to use the submit function and additional code.

Thanks

Glad you managed to figure it out!

Sorry, can you write the code for this specific example using the .save() method

On a dynamic page for the database called ‘Players’…
A value is input in to input box called ‘input1’
Submit button is pressed called ‘submit1’
I would like it to then save the value from input box ‘input 1’ into the cell for that particular player called ‘Q1’ in the database Players.

I have looked through the help pages, but I must be doing something wrong and cant find any examples to help.

Thanks