dcsimg
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,878
    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.
    STOP using $ prefix on JavaScript variable names...
    Please remember to wrap any code you have in forum tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

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