javascript problems
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Other forums
- :
- Tech Help - Software/Hardware etc
- :
- javascript problems
javascript problems
06-01-2017 10:24 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
anyone know why this script doesn't work?
var x10 = document.forms["add-absence"]["absencetype"].value; var x11 = document.forms["add-absence"]["length"].value; if ((x10 != "Medical") && (x11 == "Partial Day")) { alert("Partial Day can only be used for Medial absence"); return false; }
it's currently failing even when the x10 variable is "Medical"
basically x11 variable can only be accepted when x10 variable is "Medical".
Re: javascript problems
06-01-2017 10:30 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
it does work... i was passing the wrong data into variable x11 !
Re: javascript problems
06-01-2017 10:44 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Sorry @chenks76 got to spend my 10p here. But for what it is worth if the data types you are comparing are of the same type then ideally you should be using === and not == (or !== -v- !=) . Using === does not do type conversion meaning that the operation is that bit quicker when the types are the same.
For example if you have:
var A = ‘1’ ;
var B = 1 ;
If you then ask if (A === B) then the answer is No, as they are not the same type but asking if (A == B) then you’d get true due to the applied type conversion.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page