codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Delete an element from the form.elements array  Archive Import (quilpole) at 13:34 on Monday, July 28, 2003
 

I would like to be able to delete certain elements (selectively) from the form elements array (using an onchange handler). This goes further simply disabling an element ... I`d like to simply make it go away!

Any ideas?

  Re: Delete an element from the form.elements array  Troy Wolf at 16:52 on Monday, July 28, 2003
 

So for example, if you have a form with three text inputs, you`d like to have the ability to make one no longer exist. Well, I assume you want this to fire upon a particular event. Without doing complete page rewrites with JavaScript--which can be done, one way would be to have the page submit back to your ASP server on that event and rewrite the page back minus the form element. When you say you want it to no longer exist, are you sure that having it disabled and invisible would not be good enough? A DISABLED form element will not even show up in your Form.Request collection -- so server-side, it does not exist anymore. So now you have the problem of making it invisible to the user--this is fairly simple using styles. The code below shows an example of both disabling and making invisible a complete form element. For all practical purposes, it does not exist. Is this good enough for what you need?

(Don`t forget to fix the single ticks when you copy & paste code from the forum.)

----------------------------
<script language=javascript1.2>
function HideField(fName) {
o = document.forms[0].elements[fName];
o.disabled = true;
styleName = `s` + fName;
o = document.getElementById(styleName);
o.style.display = `none`;
}
function ShowField(fName) {
styleName = `s` + fName;
o = document.getElementById(styleName);
o.style.display = `inline`;
o = document.forms[0].elements[fName];
o.disabled = false;
}
</script>

<form>

<span id=stext1 style="display:inline"><br>Field 1: <input type=text name=text1></span>

<span id="stext2" style="display:inline"><br>Field 2: <input type=text name=text2></span>

<span id="stext3" style="display:inline"><br>Field 3: <input type=text name=text3></span>

<br><input type=button value="Make Field 2 Disappear" onclick="HideField(`text2`)">
<br><input type=button value="Make Field 2 Re-Appear" onclick="ShowField(`text2`)">

</form>
Troy Wolf: site expert
SnippetEdit Website Editor


  Re: Delete an element from the form.elements array  Troy Wolf at 16:53 on Monday, July 28, 2003
 

Um...in my previous post, "Form.Request collection" should be "Request.Form collection". oops.
Troy Wolf: site expert
SnippetEdit Website Editor









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: Append right click menu
•  Re: Frame over frame
•  Re: print using conf file
•  Re: Help: Trouble with z-Index and SELECT lists
•  Re: frame title page problem
•  Re: Print and print preview file on the website without using the File - Print on the IE
•  Re: onmouseover change image and text
•  Re: how to refresh the parent window`s parent?
•  Re: javascript, get the color assigned by class


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010