[Javascript] how to create input tag on the fly

David T. Lovering dlovering at gazos.com
Thu Jul 3 10:43:12 CDT 2003


The basic method looks OK, but I think what is biting you is the single-quote placement.  Try this
instead:

  document.write("<input type='text' name='coba" + objd + "'>"); objd++;

Also (although this is a minor point), most subsidiary object groupings start with "0" as their
base index.  No reason you should follow this convention, but it is worth thinking about.

The other thing you should think about is the precedence of when this new input gets created, and
where it gets put on the page.  Normally, the <inputs> get spun while the first run through the body
declaration is taking place.  Yes, you can add inputs later -- but usually this is done through the
"createElement("INPUT")" declaration, where you are spawning it as a child of an object already on-screen
as it were.  I usually use a table to frame these created objects, and create new rows as well whenever
I spin off another new input.

I'd try a couple of little short test routines to get familiar with the creation/destruction of new
objects using the createElement call -- I think it is your best bet.

-- Dave Lovering

andy susanto wrote:
> 
> hai,
> 
> i am try to create on the fly input tag, but the input tag always create on
> a new page.
> 
> What i want is that input tag on the same page how can i make that possible
> ?
> 
> this my script :
> 
> <FORM>
> <SCRIPT LANGUAGE="JavaScript">
> var objd=1;
> function test(){
> document.write("<input type='text' name='coba'+objd>");
> objd++;
> }
> </SCRIPT>
> 
> <input type='button' onclick='test()' Value='create inputtag'>
> </FORM>
> 
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript


More information about the Javascript mailing list