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
    New to the CF scene
    Join Date
    May 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Can you display a Global Variable value within html

    Hey folks .. long time lurker... and first post

    Have been looking for a few weeks now and no luck in finding any answer to this.. so here goes

    I have a html page that generates forms dynamically - all ok here

    What I'd like to do is really only cosmetic - but would still like to see if its possible.

    I have a legend for each form which appears as "Form Name"
    I have a Global Variable called "counter" which keeps track of the number of forms created

    What I would like to know is it possible to have my forms created so the Legend will state "Form Name 1" for the first form, "Form Name 2"

    => basically the number x in "Form Name x" is assigned on the form creation and is the value of "counter"

    Is this possible ??

    Any advice much appreciated

  • #2
    Regular Coder mbaker's Avatar
    Join Date
    Jan 2010
    Location
    Burford, Oxfordshire, United Kingdom
    Posts
    249
    Thanks
    1
    Thanked 39 Times in 39 Posts
    Yes, it is possible. However to give more advice we will need some more information.

    You say:

    I have a html page that generates forms dynamically
    Given that HTML is a static markup language, you must be using a scripting language to do this. The most likely are javascript (on the users client / browser) or PHP (on the web server).

    How to achieve the result you want will depend in no small part on which language you are using to generate your forms.

    Which language are you using?
    - Michael Baker - HTML Tags Guide - Reference and Tutorials
    - Like voting, validate early, validate often - W3C HTML Validator - W3C CSS Validator
    - Wot? me cynical? no, its just if you vote, er, validate early, you have more chance of validating often.

  • #3
    New to the CF scene
    Join Date
    May 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey mbaker,

    Thanks for your reply.

    Ok yes I'm using javascript to generate the forms

    In my HTML body I have a DIV id="template" style="display: none"
    on page load it displays one form
    Then with an "Add" button calling a javascript I add another form using the template - this is then a child of the first form

    I can include the code if it will help.

  • #4
    Regular Coder mbaker's Avatar
    Join Date
    Jan 2010
    Location
    Burford, Oxfordshire, United Kingdom
    Posts
    249
    Thanks
    1
    Thanked 39 Times in 39 Posts
    The following snippet of Javascript should point you in the right direction:

    Code:
    var counter = 5;
    var formName = "Form Name";
    var fullFormName = "";
    
    fullFormName = formName + " " + counter;
    If you need more than this, then posting your code would help.

    Michael.
    - Michael Baker - HTML Tags Guide - Reference and Tutorials
    - Like voting, validate early, validate often - W3C HTML Validator - W3C CSS Validator
    - Wot? me cynical? no, its just if you vote, er, validate early, you have more chance of validating often.

  • #5
    New to the CF scene
    Join Date
    May 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey thanks for getting back to me.. I know how to join things together..
    however what I want is to have the Global Variable displayed directly ion the html page when it is rendered.. heres my code... any ideas

    function initial_panel_form()
    {
    document.getElementById('additional_form').onclick = additional_panel_form;
    additional_panel_form();
    }
    function additional_panel_form()
    {
    counter++;
    var new_form = document.getElementById('panel_form_template').cloneNode(true);
    new_form.id = '';
    new_form.style.display = 'block';
    var next_form = new_form.childNodes;
    var index;
    for (index=0;index<next_form.length;index++)
    {
    var form_name = next_form[index].name
    if (form_name)
    next_form[index].name = form_name + counter;
    }
    var insertHere = document.getElementById('newpanel');
    insertHere.parentNode.insertBefore(new_form,insertHere);
    }


    <fieldset>
    <h1>Page Title</h1>
    <div><label for="Page Name">Page Name</label> <input id="page_name" name="page_name" type="text" onfocus="this.value==this.defaultValue?this.value='':null" /></div>
    <div id="panel_form_template" style="display: none" class="panel_class">
    <fieldset><legend>Photo Panel</legend>
    <div><label for="panel_label">Panel Label</label> <input id="panel_label" name="panel_label" type="text" onfocus="this.value==this.defaultValue?this.value='':null" /></div>
    <div><label for="search">Search Term</label> <input id="search" name="search" type="text" onfocus="this.value==this.defaultValue?this.value='':null" /></div>
    </fieldset>
    <input type="button" value="Remove Panel" onclick="remove_panel_form(this);" /></div>
    <form name="myform" id="myform" method="post" onsubmit="return validate();" action="show_flickr_search_results.php"><span id="newpanel"></span> <input type="button" id="additional_form" value="Add Panel" /> <input type="submit" value="Show Gallery" /></form>
    </fieldset>

  • #6
    New to the CF scene
    Join Date
    May 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    To clarify a bit more..

    On loading there is no form displayed *until* onpageload
    this then displayes the first form counter=1
    So I would like the form to appear showing "Panel Label 1"
    on creating the second panel the counter will be 2 so I would like the form to appear "Panel Label 2"

    write.document(counter) does not work - in simply displays counter value which is at 1 onpageload and *NO* form is displayed
    alert(counter) does display the vlaue that I expect at the time of creation of the form but again this is in an alert box.. not actually "written" in the page itself..

    AS I said earlier this is purely cosmetic - but would be nice if I could figure out how to do it


  •  

    Tags for this Thread

    Posting Permissions

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