View Full Version : Can you display a Global Variable value within html

May 9th, 2010, 07:59 PM
Hey folks .. long time lurker... and first post :D

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 ??:confused:

Any advice much appreciated

May 9th, 2010, 08:26 PM
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?

May 9th, 2010, 10:04 PM
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.

May 10th, 2010, 03:05 AM
The following snippet of Javascript should point you in the right direction:

var counter = 5;
var formName = "Form Name";
var fullFormName = "";

fullFormName = formName + " " + counter;

If you need more than this, then posting your code would help.


May 10th, 2010, 02:30 PM
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;
function additional_panel_form()
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');

<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>
<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>

May 10th, 2010, 07:57 PM
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 :D:thumbsup: