Solved

Basic Javascript Syntax

Posted on 2007-04-05
4
354 Views
Last Modified: 2010-08-05
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...
0
Comment
Question by:NTGuru705
  • 3
4 Comments
 
LVL 10

Accepted Solution

by:
geodan7 earned 500 total points
Comment Utility
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
 
LVL 10

Expert Comment

by:geodan7
Comment Utility
//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
 
LVL 10

Assisted Solution

by:geodan7
geodan7 earned 500 total points
Comment Utility
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
 
LVL 1

Author Comment

by:NTGuru705
Comment Utility
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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now