**As our CRUD (Create, Read, Update, Delete) continues, we are going to jump right on in. I want to show you how to use JavaScript itself before we rewrite the app with JQuery. Understanding the language is more important than how to use the libraries.
One of the first functions we will write is going to be a very well used one. You might actually want to save this for future use. The function needs to look at the document object, search for ids, and return the one you are looking for. First, we start out by creating a function that takes one argument, we’ll call it ge for “get element”. To create a function you simply write:
function ge(id) {
// code here
};**
Notre CRUD (Create, Read, Update, Delete ou Créer, Lire, Modifier, Supprimer) se poursuit et nous allons cette fois sauter dedans à pieds joints. Je veux vous montrer comment utiliser JavaScript lui-même avant de réécrire l'application avec JQuery. Comprendre le langage est plus important que la façon d'utiliser les bibliothèques.
L'une des premières fonctions que nous écrirons est vraiment très souvent utilisée. Vous pouvez même en fait vouloir la sauvegarder pour une utilisation future. La fonction doit regarder l'objet document, rechercher des identifiants et retourner celui que vous recherchez. Tout d'abord, nous commençons par créer une fonction qui prend un argument, nous l'appellerons ge pour « get element ». Pour créer une fonction il suffit d'écrire :
function ge(id) {
// votre code ici
};
**Now that we have a function, we need to write the code. We are searching the document object model for an id, which the document object has a function for. So let’s bring the results of that function into a variable and return it.
// gets an element by its id from the document object model (DOM)
function ge(id) {
var theElement = document.getElementById(id);
return theElement;
};**
Maintenant que nous avons une fonction, il faut écrire le code. Nous recherchons un identifiant dans le modèle d'objet document et l'objet document possède justement une fonction pour ça. Nous allons rapporter les résultats de cette fonction dans une variable et la retourner.
// Récupère un élément par son id dans le modèle d'objet document (DOM)
function ge(id) {
var theElement = document.getElementById(id);
return theElement;
};
**The line that starts with // is called a comment. This line is to help coders keep track of what is going on in their code, and allow them to leave notes for other people using their code.
The next thing is that we need to handle the form when the submit button is pressed. First, we need to give an id to the form itself. Let’s call it “ubuVersFrom”. So now, the open form tag should look like this: