0
<html>
    <head>
        <title>DisciplinasMatriculadas</title>
        <script type="text/javascript" src="index.js"></script>
    </head>
    <BODY style="font-family: sans-serif">

        <fieldset>
            <legend>Matricula de aluno em disciplina</legend>
            <form action="/myform" method="GET">
            ID Aluno: <input type="text" name="aluno" id="aluno">
            <br/>
            ID Disciplina: <input type="text" name="disc" id="disc">
            <br/>
            </form>
        <input type="button" value="Add" onclick="addDisciplina();alert('Done.');">
        </fieldset>
    </body>
</html>

Hi, I'm trying to make this onclick function work (newbie here), but I can't figure out what is the problem. Could you guys help me, please?

PS: The index.js works fine if I run it by CMD.

Thanks!

PS2: I've edited like you guys said, but still didn't work. Here's the js:

addDisciplina = function() {

var mysql = require('mysql');
var express = require('express'); 
var app = express(); 
app.get('/myform', function(req, res){ 
    var aluno = req.query.aluno;
    var disc = req.query.disc; 
}); 

var connection = mysql.createConnection({
 host: "localhost",
 user: "root",
 password: "161616",
 database: "matricula"
});

var post  = {idDisciplinasMatriculada: aluno*3+disc*2, idDisciplina: disc, idAluno: aluno};

connection.query('INSERT INTO DisciplinasMatriculadas SET ?', post, function(err, result) {});

}
4
  • 1
    There must be some error in your javascript code. Commented Jul 15, 2016 at 11:39
  • what's the code of addDisciplina(); Commented Jul 15, 2016 at 11:42
  • I've edited the original post with the code :) Commented Jul 15, 2016 at 12:23
  • The index.js is NodeJs code, it will not run by frontend side, what you need to do is to create a route(RESTFUL API), and make a ajax call or http request. Commented Jul 15, 2016 at 12:44

3 Answers 3

1

you're closing </select> while there are no <select>.

Sign up to request clarification or add additional context in comments.

Comments

0
<HTML>
<HEAD>
    <TITLE>DisciplinasMatriculadas</TITLE>
    <SCRIPT language="javascript" src="index.js"></SCRIPT>
</HEAD>
<BODY style="font-family: sans-serif">

    <fieldset>
        <legend>Matricula de aluno em disciplina</legend>
        <form action="/myform" method="GET"><select>
        ID Aluno: <input type="text" name="aluno" id="aluno"></select>
        <br/>
        <select>
    ID Disciplina: <input type="text" name="disc" id="disc"></select>
    <br/>
    </form>
<input type="button" value="Add" onclick="addDisciplina();alert('Done.');">
</fieldset>

Correct the Html and try again :)

1 Comment

I've removed the selects, they were useless, but still not working :(
0

You have some errors in HTML file. First of all, you don't need </select> at all if you don't have <select> tag opened. The <select> should be a parent of a child element <option>, for example:

<select>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>

You can use multiple onclick events, just separate them with a semicolon (;). Use <script type="text/javascript" src="index.js"></script> instead of language="javascript", you don't need it and don't forget using a lowercase symbols, it's the best practise. This is jsfiddle for you.

1 Comment

Done, but still nothing :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.