[thelist] Generating Form elements...

James Q. Stansfield jqs at iridani.net
Tue Apr 9 10:05:00 CDT 2002


This is a multi-part message in MIME format.
--
[ Picked text/plain from multipart/alternative ]
Hey guys & gals, I'm not much of a javascript progger but I want some extended functionality that I've seen before (can't 'member where (d'oh!)) but I can't seem to recreate it.

   The short of it is I'm building a form for uploading files to a website. I want the form to present itself with a single upload element, but,via script, add extra elements when people click on a button. I've got this working perfectly, except when it comes to the minus button to remove an input box. Essentially I want one boxed added, or deleted at a time.

    Here's what I've go thus far:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
 <title>UploadTest...</title>
 <script language = javascript>
 var intCount = 1;
 function doUpload(form) {
  form.action="ToFileSystem.asp?NUM=" + intCount;
  form.submit();
  }
 function addUL(form) {
  intCount++;
  document.getElementById('ularea').innerHTML = document.getElementById('ularea').innerHTML + '<div id="ul' + intCount + '" name="ul' + intCount + '"><INPUT type="File" name="File' + intCount + '"><br></div>';
  document.getElementById('count').innerHTML = intCount;
  }
 function delUL(form) {
  if (intCount>1) {

   var tmp = "ul" + intCount;
   document.getElementByID(tmp).outerHTML = "";
   intCount--;
   document.getElementById('count').innerHTML = intCount;
   }
  }
 </script>
</head>

<body>
<FORM name="ul_form" method="post" encType="multipart/form-data" action="" onSubmit="return false;">
 <INPUT type="File" name="File1"><br>
 <DIV id="ularea" name="ularea"></DIV>
 <hr>
 <INPUT type="Button" value="+" onclick="addUL(this.form)">
 <INPUT type="Button" value="-" onclick="delUL(this.form)">
 <INPUT type="Submit" value="Upload" onclick="doUpload(this.form)">
</FORM>
<div id="count"></div>
</body>
</html>


Many thanks in advance for the help...

    //James
--




More information about the thelist mailing list