How do I work with numeric variables in Netscape 3.04?
Hello,
I'm trying to make my website browsable with Netscape version 3.04, but I cant seem to perform a simple mathematical problem using js, because the user-selected numeric values are null, which makes the solution display NAN. The parseInt() solution doesn't work in NS 3.04. Does anyone know how to represent a numeric form value as a number, not as null?
Thanks,
Dan
Vincent Puglia posted this at 11:40 — 9th July 2000.
They have: 634 posts
Joined: Dec 1999
Hi,
I'm a little confused. Regardless of the version & browser, all form values are stored internally as text.
So, if you are talking about the problem found in all browsers & versions, try something like:
var x = 0;
x += document.formname.fieldname.value;
x += 6;
By declaring the var first and assigning 0 as its value, the browser should do the appropriate math.
However, what do you mean by "user-selected numeric values are null"? You have a selection list with numbers as options?
Vinny
Where the world once stood
the blades of grass cut me still
dan posted this at 15:44 — 9th July 2000.
They have: 7 posts
Joined: Apr 1999
Thanks a lot for responding, Vinny. This has been bothering me for a long time. The following snippet demonstrates the heart of the problem. I've set up three alerts to display the number selected from the select menu, and not one displays the number correctly in NS 3.04, though it is fine in IE. What am I missing?
Thanks,
Dan
<script language=javascript>
function calcbod(form)
{
var x=0;
x += form.elements[0].value;
feet = parseFloat(form.elements[0].value);
alert('unassigned is ' + form.elements[0].value);
alert('x is ' + x);
alert('feet is ' + feet);
}
</script>
2'
3'
4'
5'
6'
7'
8'
Vincent Puglia posted this at 21:36 — 9th July 2000.
They have: 634 posts
Joined: Dec 1999
Hi Dan,
You're using an infamous IE-shortcut in your alerts. In fact, it's one I've never seen.
To access selection list options, you need to use the following DOM (document object model):
document.formname.selectname.options[document.formname.selectname.selectedIndex].value;
(Mouthful, huh? That's why Microsoft made it's shortcuts)
To do what you want, I would code it like this:
function calcbod(selObj)
{
var feet = 0;
for (i=0; i < selObj.length; i++)
if (selObj.options[i].selected)
{
feet = selObj.options[i].value;
alert('feet is ' + feet);
alert('feet + 3 is: ' + (feet + 3));
}
}
2'
3'
4'
5'
6'
7'
8'
Notes:
1) I only passed "this" because it is what you need, you don't need the form (unless you put in some other field with which you do additional calculations.
2) I took out the parseFloat: parseInt(num) is what you would use, but it should work without either.
3) I use a for loop rather than send the selectedIndex because I cut and paste function templates into my code -- I've found this way to be the most compatible for what I do == regardless of whether the list is a select-one or a select-multiple.
Vinny
Where the world once stood
the blades of grass cut me still
dan posted this at 20:50 — 11th July 2000.
They have: 7 posts
Joined: Apr 1999
Hi Vinny,
I cut and pasted your code on its own new html page and it didn't work. I selected, and it did nothing. So, I commented out the actual loop, but the select value still displayed as null. I also tried filling in that DOM variable with the proper values - just got an error. Did you actually try that code out in NS 3.04? Can this be done like I did using the elements array instead of the input object name. I have about 20 other input objects that I'm working with?
Thanks,
Dan
TheGraphicsExpe... posted this at 22:12 — 11th July 2000.
They have: 184 posts
Joined: Jun 2000
NS3.04 is out of date.
In fact... it's seriously out of date.
Why not just bypass the whole thing and just set up a browser redirection script that recommends that people update to the newest version?
I mean, come on... if people are not--by now--using a 4.0 browser, then as a friend of mine said 'they shouldn't be using the internet at all.'
Backwards compatibility is good and all, but here's where you stop and ask yourself: Is it -worth- the trouble?
Mike Fisher
Hypertrophy (design)
[email protected]
ICQ: 38389521
"Taking over TWF, one post at a time."
Vincent Puglia posted this at 01:30 — 12th July 2000.
They have: 634 posts
Joined: Dec 1999
Hi Dan,
My fault -- I forgot to put in the
maybe not -- the board is chewing it up -- an opening "[" and "i" and a closing "]"
function calcbod(selObj)
{
var feet = 0;
for (x=0; x < selObj.length; x++)
if (selObj.options[x].selected) ////// put the index here -- an opening "[" and "i" and a closing "]"
{
feet = selObj.options[x].value; // ditto
alert('feet is ' + feet);
alert('feet + 3 is: ' + (feet + 3));
}
}
I didn't test with version 3 -- I don't have it. And I don't really know anyone who does. However, if it doesn't work with the correction, it won't work, and you'll have to follow theGraphicExperience's advice -- advise people to upgrade -- either that or not use selection lists and the DOM (I don't remember in which version the two were first supported by Netscape.) If you absolutely have to support ver 3, let me know.
Hi theGraphicsExperience: In theory, you're right, but I can think of at least one user-type that would be extremely reticent to the concept of upgrading browsers -- a school district. I've helped individuals around the world (Australia, New Zealand, Malta, etc) who had to program in backward compatibility, and it wasn't easy.
Vinny
[Edited by Vincent Puglia on 07-11-2000 at 09:35 PM]
Where the world once stood
the blades of grass cut me still
dan posted this at 02:16 — 13th July 2000.
They have: 7 posts
Joined: Apr 1999
Ahh, finally got it!
Thanks tons for your help, Vinny. Thanks for the input theGraphicsExperience. Both the Community College and the public library by where I live are STILL using NS3, so I'm just assuming it is like this elsewhere, although I totally agree that no serious surfer should be using any thing less than 4, but what can you do?
Thanks again for your help,
Dan
Vincent Puglia posted this at 12:05 — 13th July 2000.
They have: 634 posts
Joined: Dec 1999
Hi Dan,
no prob. suspected the nn3 was being used by some educational facility -- amusing how it's ok to spend money to 'string them up' rather than 'teach them right' As Dylan said, "When will they ever learn?" (bob, not thomas)
Vinny
Where the world once stood
the blades of grass cut me still
Lloyd Hassell posted this at 15:58 — 15th July 2000.
They have: 231 posts
Joined: Feb 2000
If you do come across people using older browsers (especially netscape) why don't you just tell them their browsers are out of date. Most people don't realise the limitations surfers have with older browsers and the headaches that they give to the developer. Education is the key.
:: Lloyd Hassell :: http://www14.brinkster.com/lloydh ::
Vincent Puglia posted this at 23:08 — 16th July 2000.
They have: 634 posts
Joined: Dec 1999
Hi Lloydd,
While I may agree with you in principle, I don't believe it is wise to force people to choose between what is and what should be, especially if those people are the ones paying your salary, so to speak.
Vinny
Where the world once stood
the blades of grass cut me still
Lloyd Hassell posted this at 16:12 — 17th July 2000.
They have: 231 posts
Joined: Feb 2000
Vinny: I am not saying to force them to change, just saying that you should suggest it to them. Most people don't realise how easy it is update a browser.
:: Lloyd Hassell :: http://www14.brinkster.com/lloydh ::
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.