Alex,When you are initializing x, you are first getting a string type back from the form.ihn.value property, and then you are passing it to eval(), which then will evaluate the string as if it is an expression. (This is one of the things I find troubling about loosely typed languages! You have to manage all of the data typing in your head instead of knowing it explicitly by glancing at the code.) That is why you will get '13' out of the value property and 4 out of eval(). In any case, one of the oldest debugging techniques in the javascript world is to insert an alert() function call her and there to see what you are getting out of your assignments. If you find that alert(x); returns 'undefined' or something strange like that, you will have a place to begin working toward a solution to your problem.
Good luck! - Jeff----- Original Message ----- From: "Alex Hall" <mehgcap@xxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx> Sent: Wednesday, February 06, 2008 10:49 PM Subject: Re: a quick js code question
Yes, I tried it both ways. I have found, though, that not using eval() causes 1+3 to equal 13, while using eval() gives me 4, which is the type of answer I am looking for.Have a great day, Alex----- Original Message ----- From: "Jeffrey Fidler" <jfiddler2@xxxxxxxxxxx To: <programmingblind@xxxxxxxxxxxxx Date sent: Wed, 6 Feb 2008 22:32:08 -0500 Subject: Re: a quick js code questionAlex,eval() will evaluate a string argument. Did you try to just usetheassignment operator to initialize your variable? i.e. var x = form.in.value;HTH!- Jeff----- Original Message ----- From: "Alex Hall" <mehgcap@xxxxxxx To: <programmingblind@xxxxxxxxxxxxx Sent: Wednesday, February 06, 2008 10:08 PM Subject: a quick js code questionHi all, I have a very simple program that, for some reason refuses torun. I havethis function being called by a button and that part works, butI cannotget an answer out of this function. It seems to stop at where Ideclare xas a variable. The code, all 12 lines of it, is below. Ifanyone canpoint out what I know must be a very simple error I would really appreciate it. function eq(){ try{ x=eval(form.in.value); ans=(x-2)/(x*x)-4; form.out.value=ans;catch(err){ alert(err+": "+err.description);Have a great day, Alex __________ View the list's information and change your settings at //www.freelists.org/list/programmingblind__________ View the list's information and change your settings at //www.freelists.org/list/programmingblind__________View the list's information and change your settings at //www.freelists.org/list/programmingblind
__________View the list's information and change your settings at //www.freelists.org/list/programmingblind