Using Javascript to start a function on spark core

Hey, I’m attempting to make a program to use arrow keys in javascript in order to start a function in the code for the core. However, the program is not functioning, and I’ve deduced the issue to be coming from the Javascript program(I am completely new to it). Here is the code I have for the core with filename motorcontroller:

int motor1 = D0;
int motor2 = D1;
int ms = 1.5; //ms for logic


void setup() {
    pinMode(motor1, OUTPUT);
    pinMode(motor2, OUTPUT);
    Spark.function("motor1drive", motor1drive);
    Spark.function("motor1stop", motor1stop);
    Spark.function("motor2drive", motor2drive);
    Spark.function("motor2stop", motor2stop);
    
}

void loop() {
}

int motor1drive(String command) {
    if(command=="motor1drive") {
        for(int i=0; i<255; i++) {
        analogWrite(motor1,255); 
        delay(ms);
        analogWrite(motor1,0);
        delay(ms);
        }
    }
}
int motor1stop(String command) {
    if(command=="motor1stop") {
        analogWrite(motor1,0);  
        delay(ms);
        analogWrite(motor1,0);
        delay(ms);
    }
}

and here is the code I have for Javascript:

<html>
	<script src="https://api.particle.io/v1/devices/DEVICEID/motorcontroller?access_token=ACCESSTOKEN" ></script>
	
	<script>
	document.onkeydown = function(e) {
    switch (e.keyCode) {
        case 37:
            alert('left');  
            document.forms["motor1drive"].submit();
            break;
        case 38:
            alert('up');
            document.forms["motor1stop"].submit();
            break;
        case 39:
            alert('right');
            break;
        case 40:
            alert('down');
            break;
    }
};
</script>

</html>

I believe the issue is this:

                document.forms["motor1drive"].submit();

but I dont know what to change it to. Thanks.

PS Im not sure if any of the Javascript is correct

I moved a post to an existing topic: Reading HTML form name in Spark Core programming

This topic is now closed. New replies are no longer allowed.

You’ve asked this question before, multiple times, on different topics. It’s been answered there already. I see no reason to open up a new topic for that. Please try to keep related topics together, and try using search before opening new ones.