How to get value from span element in Firefox?

Posted on 2008-10-24
Last Modified: 2013-12-08
Hi all,

The script below works as expected in IE6 and IE7.  When I try it in FF3, it returns a NaN where IE returns an actual value.  For testing purposes, this script just doubles the selected value in the list and outputs it to a span element.

I've even included an isNaN() test, but it's still not working.

Can anyone make this work in both IE and FF?

Any help much appreciated.

Thank you,




function updateprice(labelParam, selectParam, spanParam) { // output area, number selected, item value

// query DOM set for specific elements by ID

var label = document.getElementById(labelParam);

var name = document.getElementById(selectParam).value;

var spanval = parseInt(document.getElementById(spanParam).value);

if (isNaN(name)) { 

	name = "0"; 

	name = parseInt(name); 

	alert("name problem. val: " + name);


if (isNaN(spanval)) { 

	spanVal = "0"; 

	spanVal = parseInt(spanVal); 

	alert("spanval problem. val: " + spanVal);


var total = parseInt(name)*parseInt(spanval);

msg = "Result: " + total;

label.innerHTML= msg;








    <select name="select1" id="select1" onchange="updateprice('output1','select1','item1');">

      <option value="0">0</option>

      <option value="1">1</option>

      <option value="2">2</option>

      <option value="3">3</option>




<span id="item1" name="item1" value="2"></span><br>

<span id="output1" name="output1"></span><br>



Open in new window

Question by:paulc2000
LVL 82

Accepted Solution

hielo earned 500 total points
ID: 22797598
var spanval = parseInt(document.getElementById(spanParam).getAttribute("value"));

Author Comment

ID: 22797646
Short and sweet!  It worked, thank you very much!

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

937 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

5 Experts available now in Live!

Get 1:1 Help Now