473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

My first Javascript, is there a better way?

I decided for my first Javascript program, I would port a php currency
conversion utility. However I've come to find out that something
critical was missed during the design phase. That is that
XMLHttpRequest does not function in this circumstance at all, I keep
getting permission denied errors (I'm working in Firefox). Would
someone mind taking a look at the following script and letting me know
if there was maybe a better way, or can this even be done in
Javascript?

Thanx in advance for the help.

function loadXMLDoc(url){
// branch for native XMLHttpRequest object
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send(null);
// branch for IE/Windows ActiveX version
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send();
}
}
}

function processReqChange(){
// only if req shows "complete"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
// ...processing statements go here...
response = req.responseXML.documentElement.data;
alert("Response was recieved!:\n");
eval(checkRate + '(response)');
} else {
alert("There was a problem retrieving the rate data:\n" +
req.status);
}
}
}
function checkRate(response)
{
alert("checkRate was entered!:\n");
if (response){
// Response mode
alert("Response was not NULL, response is :\n" + response);
if (response == '1'){
message.className = 'error';
}else{
fromprice = document.getElementById('currency_amount').value;
price = fromprice * response;
fromprice.value = price;
}
}else{
// Input mode
fromcur = document.getElementById('currency_from').value;
tocur = document.getElementById('currency_to').value;
url =
'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=l1&s='+fromcur+tocur+'=X';
alert("url is :\n" + url);
loadXMLDoc(url);
}

}

Oct 16 '05 #1
1 1115
sm*****@gmail.com wrote:
I decided for my first Javascript program, I would port a php currency
conversion utility. However I've come to find out that something
critical was missed during the design phase. That is that
XMLHttpRequest does not function in this circumstance at all, I keep
getting permission denied errors (I'm working in Firefox). Would
someone mind taking a look at the following script and letting me know
if there was maybe a better way, or can this even be done in
Javascript?


Without special security measurements, this can only work when the request
is performed on the same server. One of these measurements consists of
signing your scripts. See the following page for more information:

http://www.mozilla.org/projects/secu...d-scripts.html

An easier solution, however, would be to have a local PHP script retrieve
the content from Yahoo, afterwhich you can parse its response with
JavaScript.
JW

Oct 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Sergio del Amo | last post by:
Hi, I am trying to create a web site to work in Opera 7.2, Explorer 6.0 and Mozilla 1.4. I have the code: var imgs= document.getElementsByTagName("img"); alert(imgs.id); The id of imgs is...
53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
111
by: Retlak | last post by:
The recommended (on dozens of websites) and effective (works in Netscape, MSIE, Mozilla, probably others) way to detect if a browser has Javascript turned off is to put this in the <head>: ...
3
by: Gord | last post by:
http://eastontario.com/promo/tableCellMultiplier.htm For a rectangular/square n column, m row table, this script formats so that all cells hold the same contents. Check out the source and vary...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
14
by: Sinity | last post by:
Anyone knows the method/codes to disable the clicked button after first click by using .aspx-- to prevent people to click many time when waiting for the server response. I tried to do this by...
5
by: Jozef | last post by:
Hello, I have done a little "old" ASP work along with some javascript. I'm currently getting into ASP.net and would like to step up my game overall with regard to Web Development. I was...
18
by: barry | last post by:
I'm having a problem creating a delay before each list item gets moved ( http://www.polisource.com/PublicMisc/list-splitter-timeout-bug.html ). Choose any number of columns, vertical layout, and...
44
by: user | last post by:
Hi, Let's say I have 2 dates in the b/m format: Date 1 and date 2 How do I check whether Date2 is later than Date 1? Date1. 21-Nov-2006 09:00:00 PM
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.