Solved

How to get value from span element in Firefox?

Posted on 2008-10-24
2
2,407 Views
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,

Paul.
<html>
<head>
<script>
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;
}
 
 
</script>
 
<title>Doubler</title>
</head>
 
<body>
<form>
  <p>Doubler:
    <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>
    </select>
  </p>
</form>
 
<span id="item1" name="item1" value="2"></span><br>
<span id="output1" name="output1"></span><br>
</body>
</html>

Open in new window

0
Comment
Question by:paulc2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 82

Accepted Solution

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

Author Comment

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

Featured Post

Create Professional Looking Email Signatures

Create "Professional HTML Email Signatures" with ease.
7 Day Money Back Guarantee if not 100% Satisfied.
Affordable - Try it out for 7 Days Totally Risk Free.
Installers provided for over 45 Email clients.
Both Windows & MAC Supported.
Highly Recommended!

Question has a verified solution.

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

Suggested Solutions

SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

751 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