Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
What is wrong with this line?
Message
De
07/12/2015 13:41:09
 
 
Information générale
Forum:
Javascript
Catégorie:
Autre
Divers
Thread ID:
01628592
Message ID:
01628600
Vues:
38
You could take advantage of JavaScript's auto coertion
var myElt = document.getElementById("MyInputText");
var myVar = myElt ? myElt.value : null; // ternary operator similar to VFP's Iif()
>>>>What could be wrong with the following javascript line?
>>>>
>>>>
>>>>var MyVar = document.getElementById("MyInputText").value;
>>>>
>>>>
>>>>I have nothing in the javascript but the above line and Alert() after this line.
>>>>If I comment the above line, the Alert() fires. Otherwise, Alert() never fires. So I think there is something wrong with the above line.
>>>>But what?
>>>
>>>Well, you need to first test if document.getElementById returns an object. So, I would use two lines and check for object first. You also need to be sure that the id you're passing matches the id of the element.
>>>
>>>https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById
>>
>>How do you check/test if document.getElementById returns an object?
>
>var myElement = ...
>if (myElement!=null)
> ....
>
>It is explained in the link.
Thierry Nivelet
FoxinCloud
Give your VFP application a second life, web-based, in YOUR cloud
http://foxincloud.com/
Never explain, never complain (Queen Elizabeth II)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform