Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing a returned value from a function.

Status
Not open for further replies.

derrickorama

Programmer
Jun 30, 2006
25
US
I'm trying to do something simple that works in Firefox, but apparently not IE. I'm just trying to store the returned value from a function into a variable. I made a simple example for myself to test. It still didn't work, so I was wondering what was wrong, and how to accomplish this task if IE can't comprehend it. Let's pretend that I press a button and it calls the 'alertMe' function.

JavaScript:

function alertMe() {
newval = getValue();
alert(newval);
};

function getValue() {
return 3;
};


Does this just not work in IE??? When I do this in Firefox, it alerts me: "3". In IE it says: "Object doesn't support this property or method". What do I do?
 
Nevermind!!!! I figured it out shortly after posting this. In Firefox it's okay to store a value with the same name as an ID on the page. My INPUT tag had an ID: "newval" and my variable was also called "newval". Firefox was fine with that, but IE didn't like it! Ugh... I gotta stop using Firefox so much, it's making me lazy.
 
Ugh... I gotta stop using Firefox so much, it's making me lazy.

Are you being serious?

-kaht

[small]How spicy would you like your chang sauce? Oh man... I have no idea what's goin' on right now...[/small]
[banghead]
 
lol... In a way yes. I got into the habit of programming my Web pages for Firefox to begin with, and then I try them on Internet Explorer and things don't work. So then I have to tweak my code so that Internet Explorer is happy. I just find that many things that work for Firefox won't work for IE, but on the other side, things that I program for IE usually work for Firefox.
 


THAT'S TOO FUNNY!!!

Usually people here are complaining that it's the other way around!

Could it be that it works both ways?


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
the root cause was probably the fact that you decided to implicitly declare a variable, not using the "var" prefix.

i doubt this gives you the same results in IE:

Code:
function alertMe() {
    var newval = getValue();
    alert(newval);
}

function getValue() {
    return 3;
}

and what's with the semi-colons after the function declaration?



*cLFlaVA
----------------------------
[tt]( <P> <B>)[sup]13[/sup] * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Ha! Yea, makes sense. And the semi-colons is part of a habit I got into whilst programming PHP.

Semi colons after everything!!!;
 
Cory, this is the javascript forum. Keep the topics off PHP. kthxbye

-kaht

Looking for a puppy?

[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top