Solved

To dynamically generate the HTML file!!

Posted on 2003-10-27
4
152 Views
Last Modified: 2010-04-09
Hi experts,
I have to generate an HTML form such that..
say first I'll display some text box & an input button (radio, checkbox..) to find if the user wants to enter some more data or not. If he wants to enter some data I have to dynamically generate a form which is similar to first form. And all the text boxes & buttons must have unique names so that I can retrieve all the values entered by the user.
0
Comment
Question by:mmveeru
4 Comments
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9627272
Is this a school assignment or are you being paid to do something you cannot?

1) create the original page
2) get your vals
3) use document.write to write
4) loop to create the field elements & unique names (doc...('<input type="text" name="text"' + i + '>')

post some code

Vinny
0
 
LVL 3

Expert Comment

by:vosk
ID: 9627600
That's how I would do, althought the question was not precise on which more data the user can enter:

<html>
<head>
<script language="JavaScript">
function A(v)
{
document.getElementById('q1').innerHTML = "<big>-</big>How many questions would you like more?<br><select name='d' onChange='B(this.value);'><option value='0'>Select from here...\n<option value='1'>1 more\n<option value='2'>2 more\n<option value='3'>3 more\n<option value='4'>4 more\n</select>";
document.getElementById('qd').innerHTML = "<big>-</big>Click <span style='cursor:hand;text-decoration:underline' onClick='Del();'>here</span> to reset.";
}
function B(n)
{
var i;
if (n!=0)
      {
      document.getElementById('q1').innerHTML = "";
      for (i=1;i<=n;i++)
            {
            document.getElementById('q1').innerHTML += "<big>-</big>Question nº "+i+" :<br><input type='text' name='question"+i+"' value=''><br><br>";
            }
      document.getElementById('q1').innerHTML += "<input type='button' name='submit' value='Submit...' onClick='C();'><br>";
      }
}
function C()
{
alert("force here to submit");
document.getElementById('ff').submit();
}
function Del()
{
document.getElementById('q1').innerHTML = "<big>-</big>Want to resp. more?<br><input type='button' name='b' value='Yes, show more...' onClick='A();'><input type='button' name='c' value='No, submit now.' onClick='C();'><br><br>";
document.getElementById('qd').innerHTML = "";
}
</script>
</head>
<body>
<form name="ff" action="sss.ext" method="post">
<big>-</big>Name:<input type="text" name="a" value=""><br><br>
<div id="q1">
<big>-</big>Want to resp. more?<br>
<input type="button" name="b" value="Yes, show more..." onClick="A();">
<input type="button" name="c" value="No, submit now." onClick="C();"><br><br>
</div>
<br><br>
<div id="qd"></div>
</form>
</body>
</html>

the method to add new fields is similar as the posted by Vincent, a simple loop between 1 and the variable. Althought that sample isn't complete, because when you pass the form to a serverside script, you may have the fields that really exists on the page; so the best way to complete is to add a srting with an 'array' format, where inform all the variables that have been used on the page. Then the serverside will get first only that array, will separate all the variables and finally it knows the names of the fields from will get values.

jbosch(vosk)
0
 
LVL 2

Accepted Solution

by:
Yavor_01126 earned 25 total points
ID: 9679227
Hi !

I am not so JScript-er but I will help because I think there must be a bit of knowledge in that work and it does matter the experience !

As I love to say HUMAN KNOWLEDGE BELONGS TO THE WORLD !   ;-)

I am an open source programer which gladly helps !  :)

So I'll consider that there are several languages for "dynamic" in HTML :

1.   JScript(Java Script) / VB Script   -   these are script languages which are used in the html file to make not HTML but more XHTML . XHTML or DHTML  are HTML but extended . What you can do with these languages is to put restricts or add interactivity or stuff like that

2.    Java / Perl / ASP ...     These are more languages than scripts !  Java is a language , while Perl is more a script and ASP is writen in JS or VB script so you decide which to coose for the job ! But Java is language which said that it is the powerfull way of doing something in HTML or at all web oriented . JSP (Java Server pages) is used for the job and servlets are just perfect !
HTML can be very extended with Java or CGI (Perl).
Perl is compilated sometimes so that means it is powerfull enough !
ASP is MS bassed so I preffer not to say any bad words fo MS :))

The main question is still not answered because I don't catch what you meen in dynamic ?

Dynamic may be :

1.   Gen. of  DB or simply text or something like that
2.   Images or interactivity in the page
3.   Ionteracting with DB(data base) to store info for users and like in 1. to gen or simply to add some text
4.   .... I can't say more for now  ;-)

If you want simply to add interactivity then try Flash ! I think you'll lern it quite fast ...

If you want a peace of source then just say it and someone will wright it for you but if not ! Then just ask this question in the wright order ;-)


Regards from BG
         Yavor
0
 

Author Comment

by:mmveeru
ID: 9692192
Hi!

thank you for ur suggestions

warm regards
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now