View Full Version : Output to Span Tag Rather Than Textfield

11-03-2006, 03:30 PM
Hey Guys,

I've got the following page below. Instead of the function writing to textfields, I want to write to span tags, which will be blank to start out with, then populate with the data after the function runs. This should be simple, but I'm not getting the syntax right for some reason. Here's the page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Sum example</title>
var ds1 = new Spry.Data.XMLDataSet("classes.xml", "classes/class");
function sumIt(i){
var class1 = 0;
var class2 = 0;
var class3 = 0;
var x = 0;
for (x = 0; x < i; x++){
var id = (ds1.getData()[x]["class"]);
if (id == 'class1'){
class1 = class1 + 1;
else if(id == 'class2'){
class2 = class2 + 1;
else {
class3 = class3 + 1;
document.form1.textfield.value = class1;
document.form1.textfield2.value = class2;
document.form1.textfield3.value = class3;
<p>If correct:</p>
<li>Class 1 = 4</li>
<li>Class 2 = 6</li>
<li>Class 3 = 7 </li>
<form id="form1" name="form1" method="post" action="" spry:region="ds1">
<label>Class 1
<input name="textfield" type="text" size="4" />
<label>Class 2
<input name="textfield2" type="text" size="4" />
<label>Class 3
<input name="textfield3" type="text" size="4" />
<div spry:region="ds1">
<p onclick="sumIt('{ds_RowCount}');">Click Me</p>


Any suggestions would be greatly appreciated.


11-03-2006, 03:46 PM
document.getElementById("foo").innerHTML = "bar";


11-03-2006, 04:40 PM
Perfect, thanks. Now how can I get that to happen when the page loads, rather than having to click a button to hit the function? I tried removing the function altogether but that isn't working ..

Thanks again ..

11-03-2006, 04:43 PM
window.onload = function(){


11-03-2006, 05:49 PM
Thanks. I'm messing with some Spry stuff, so it's still not working, but I'll keep messing around with it.

Thanks again.

11-03-2006, 09:00 PM
Okay, I have it working when the span tag it all by itself on the page. With this:

//document.getElementById("class1").innerHTML = class1;

However if the span is within a parent DIV tag, it doesn't work. I get an error with:

Error: document.getElementById("class1") has no properties

Does anyone know how I can reference the span tag within a parent DIV?