Basic Javascript Syntax

Lets talk Javascript... I am a MS freak and I dont know anything about Javascript.  But I have to write some code in javascript...my problem is not with concept but with syntax... I will post a few questions here and hopefully you guys can point me in the right direction...

1. In vbscript you say:
If MyVar IS NOT NOTHING
'DO SOMETHING
How do you say in js?

2. In vbscript you say:
for(i=0 to MyArray.Length)
'DO SOMETHING
Next
How do you say in js?

3. In vbscript you say:
for each value in MyValues
MsgBox(value.Property)
next
How do you say in js?

4. When working with ActiveXObject() what needs to be declared and what does not.  If the object returns a different object in vbscript you can just say this...
Set HTTP = CreateObject("MSXML2.XMLHTTP")
Set xmlDOC =CreateObject("MSXML.DOMDocument")
xmlDOC.Async=False
Dim MYURL
HTTP.Open "GET",URL, False
HTTP.Send()
bOK = xmlDOC.load(HTTP.responseXML)
if Not bOK then
      Set GetXMLDOC = nothing
Else
      Set GetXMLDOC = HTTP.responseXML
end If

In the above example GetXMLDOC  will be the return from that method... so if this were a funtion the caller would then be able to make use of that value... hwo to use in javascript though?

Thanks for your help...
LVL 1
NTGuru705Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

geodan7Commented:
1. if (x!=null && x!="") {
//Do something
}

2. for (i=0;i<myArray.length;i++) {
//Do Something
}

3. There is no foreach loop in javascript, but they do have a "for ...in" loop, to loop over each value
for (i in myArray) {

}
http://www.devguru.com/technologies/javascript/11477.asp

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
geodan7Commented:
//Creating and setting the instance of appropriate XMLHTTP Request object to a "XmlHttp" variable function CreateXMLHTTP(){      try      {            XMLHTTP = new ActiveXObject("Msxml2.XMLHTTP");      }      catch(e)      {            try            {                  XMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");            }             catch(oc)            {                  XMLHTTP = null;            }      }      //Creating object in Mozilla and Safari       if(!XMLHTTP && typeof XMLHttpRequest != "undefined")       {            XMLHTTP = new XMLHttpRequest();      }}
0
geodan7Commented:
Sorry about the formatting on the last post...just copy and paste it out of there. Here's another snippet for creating and loading xml:

function loadXMLDoc(dname)
{
var xmlDoc;
// code for IE
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Your browser cannot handle this script');
}
xmlDoc.async=false;
xmlDoc.load(dname);
return(xmlDoc);
}
0
NTGuru705Author Commented:
Can you help me actually use the above function.. I actually need to make a call to the webservice across the net (http get) and then use the returned data...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.