SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2004
    Location
    Brazil
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing inner.HTML variable to a DIV though button (onClick)

    Hi all,

    I´ve created a few variables to be shown in a single DIV through the "inner.HTML" process. The variables are all ok and they work fine, but I just cannot make my links to click and make the DIV receive the variables I try to to inherit.

    Here´s the JS code and the HTML one.

    JS
    Code:
    function sigem()
    {
      // Deferimento do script *Necessário*
      var sigem_1, sigem_2, sigem_3="<SCRIPT DEFER>";
      sigem_1 = sigem_1, sigem_2 = sigem_2, sigem_3 = sigem_3 + "</SCRIPT" + ">";
      
      // Variáveis de Título
      var titulo_financas = "<h1>Sigem Finanças</h1>";
      var titulo_educacao = "<h1>Sigem Educação</h1>";
      var titulo_legislativo = "<h1>Sigem Legislativo</h1>";
      
      // Variáveis de texto
      var texto_financas = "<p>test 1</p>";
      var texto_educacao = "<p>teste 2</p>";
      var texto_legislativo = "<p>test 3</p>";
       
      // innerHTML
      sig.innerHTML = titulo_financas + texto_financas; 
    }

    Here´s the HTML:

    Code:
    <a href="#" onclick="sigem( 'sig.innerHTML = titulo_financas + texto_financas;' )">Sigem Finanças</a>
    <a href="#" onclick="sigem( 'sig.innerHTML = titulo_educacao + texto_educacao;' )">Sigem Educação</a>
    <a href="#" onclick="sigem( 'sig.innerHTML = titulo_legislativo + texto_legislativo;' )">Sigem Legislativo</a>
    
    
    <div class="teste_sigem" id="sig">
    </div>
    thanks all!

  2. #2
    SitePoint Addict dek's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    at the top of your function, try:

    Code:
     var sig = document.getElementById('sig');
    I'm unsure however (amongst other things) what the argument you're providing to sigem() is intended to do.
    Only dead fish go with the flow

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2004
    Location
    Brazil
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Dek,


    I´m try to create variables with different texts in order to the user when click on a link, the Div gets populated with the refferent text of choice.

  4. #4
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Belerofonte
    Hi Dek,


    I´m try to create variables with different texts in order to the user when click on a link, the Div gets populated with the refferent text of choice.
    If you want to pass a variable to a function, you have to declare the function with said variable as a parameter:
    Code:
    function sigem(displayText) {
       document.getElementById('sig') = displayText;
    }
    When you call sigem(displayText), the function will write whatever is in displayText into the item with 'sig' as the id. Clicking on
    Code:
    <a href="#" onclick="sigem(displayText)">Text</a>
    will write "displayText" into a div with the id "sig". Make sense?


Bookmarks

Posting Permissions

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