www.webdeveloper.com
Results 1 to 2 of 2

Thread: insert text

  1. #1
    Join Date
    Jul 2014
    Posts
    1

    insert text

    I am trying to insert text using a script and having trouble:
    <script>
    var ga[];
    ga[0] = "Joe";
    function dataarrayinsert(){
    return ga[0];
    }
    </script>

    <div>
    <mark>Name: </mark>
    function dataarrayinsert()
    </div>

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,511
    I should say so.

    For one, you don't declare an array like you have or use a function like that and how are you to insert something in to a tag if you have no way of hooking the HTML element.

    To declare an array...
    Code:
    var ga = new Array();
    To declare an array with elements already set
    Code:
    var ga = new Array("Joe");
    The short cut method of creating an array
    Code:
    var ga = [];
    The short cut way of making an array with elements
    Code:
    var ga = ["Joe"];
    Declare a function
    Code:
    function someFunction(){
    do stuff
    }
    or
    Code:
    someFunction = function(){
    // do stuff
    }
    Call the function
    Code:
    someFunction();
    Any JavaScript has to be wrapped in html <script></script> tags.

    To add something to the <mark> tag, you would need to give it an id, then hook that id, then manipulate it, eg.

    HTML Code:
    <script>
    var ga = ["Joe"];
    
    function someFunction(t,data){
        o=document.getElementById(t);
        o.innerHTML = o.innerHTML + " "+data;
    }</script>
    <div>
    <mark id="targetID">Name: </mark>
    </div>
    <script>someFunction('targetID',ga[0]);</script>
    I hope that this has been of some benefit to you.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles