Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jul 2003
    Posts
    601
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Output to Span Tag Rather Than Textfield

    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:

    Code:
    <!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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Sum example</title>
    <script>
    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;
    }
    </script>
    </head>
    <body>
    <p>If correct:</p>
    <ul>
      <li>Class 1 = 4</li>
      <li>Class 2  = 6</li>
      <li>Class 3 = 7 </li>
    </ul>
    <form id="form1" name="form1" method="post" action="" spry:region="ds1">
      <label>Class 1
      <input name="textfield" type="text" size="4" />
      </label>
      <p>
        <label>Class 2
        <input name="textfield2" type="text" size="4" />
        </label>
      </p>
      <p>
        <label>Class 3
        <input name="textfield3" type="text" size="4" />
        </label>
    </p>
    </form>
    <div spry:region="ds1">
    <p onclick="sumIt('{ds_RowCount}');">Click Me</p>
    </div>
    
    </body>
    </html>
    Any suggestions would be greatly appreciated.

    Thanks.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    document.getElementById("foo").innerHTML = "bar";

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    Regular Coder
    Join Date
    Jul 2003
    Posts
    601
    Thanks
    17
    Thanked 0 Times in 0 Posts
    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 ..

  • #4
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Code:
    window.onload = function(){
      yourFunctionName();
    }

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #5
    Regular Coder
    Join Date
    Jul 2003
    Posts
    601
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Thanks. I'm messing with some Spry stuff, so it's still not working, but I'll keep messing around with it.

    Thanks again.

  • #6
    Regular Coder
    Join Date
    Jul 2003
    Posts
    601
    Thanks
    17
    Thanked 0 Times in 0 Posts
    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?

    Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •