0

I trying to get two different functions to be called when an onClick button is clicked.

<button id="button" type="button" onClick={write, message}> 
    RESERVE ROOM
  </button>

  <p id="bodyid"></p>

my write function looks like:

const write = () => {
var AWS = require("aws-sdk");
let awsConfig = {
    "region": "us-west-2",
    "endpoint": "http://dynamodb.us-west-2.amazonaws.com",
    "accessKeyId": "AKIATXDQF3UYRZVGEAEG", "secretAccessKey": "4azvTl67U8QW1id0j8***/rAOqmEp4ajnKFb9***"
};
AWS.config.update(awsConfig);

let docClient = new AWS.DynamoDB.DocumentClient();

let save = function () {

  var fullname = document.getElementById('name').value;
  var cap = document.getElementById('selectcap').value;
  var date = document.getElementById('meetingdate').value;
  var time = document.getElementById('selecttime').value;
  var room = document.getElementById('selectroom').value;
  var duration = document.getElementById('selectduration').value;

    var input = {
      "resID": 2, "Capacity": cap, "Date": date, "Duration": duration, "roomID": room, "Time": time, "FullName": fullname
    };
    var params = {
        TableName: "Reservations",
        Item:  input
    };
    docClient.put(params, function (err, data) {

        if (err) {
            console.log("users::save::error - " + JSON.stringify(err, null, 2));                      
        } else {
            console.log("users::save::success" );                      
        }
    });
}

save();
};

The message function:

const message = () => {
document.getElementById("bodyid").innerHTML = "ROOM HAS BEEN 
RESERVED!";
 };

The write function writes data inputted into a form in my data table. message just displays a message after the button is clicked.

SuperStormer
  • 4,997
  • 5
  • 25
  • 35
  • 2
    Does this answer your question? [How to call multiple JavaScript functions in onclick event?](https://stackoverflow.com/questions/3910736/how-to-call-multiple-javascript-functions-in-onclick-event) – code May 11 '21 at 19:20
  • `onclick="write(); message();"` – Barmar May 11 '21 at 19:22

1 Answers1

0

Just encapsulate them in a single callback:

<button id="button" type="button" onclick="reserveRoom()"> 
    RESERVE ROOM
</button>

function reserveRoom() {
  [write, message].forEach(x => x());
}
Guerric P
  • 30,447
  • 6
  • 48
  • 86