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:
  passing value in to function  david_ste at 16:01 on Monday, September 08, 2003
 

Basically I have created a function to blank text boxes on my form.
And yes I am fairly new to this stuff.

function deleteDeputy(number) {
window.document.deputieslist.Forename_ammend_ & number & .value = "");
window.document.deputieslist.Surname_ammend_ & number & .value = "");
window.document.deputieslist.UserID_ammend_ & number & .value = "");
}

I have used the function without passing the number value in to it just setting Forename_ammend_0 instead of Forename_ammend_ & number and it works so I must be needing to add quotes or something somewhere.

The way I call the function is

<input type="button" name="delete" value="delete" onClick="deleteDeputy('<%=i%>'">

Where i is am incremented variable. and is definately passing the correct value.


Thank you for any help in advance.



  Re: Process form element names dynamically  Troy Wolf at 17:20 on Monday, September 08, 2003
 

Hi, david_ste. You are almost there! This will do it for you:

<script language=javascript>
function deleteDeputy(number)
{
var f = document.deputieslist;
var elementName = "Forename_ammend_" + number;
f.elements[elementName].value = "";
var elementName = "Surname_ammend_" + number;
f.elements[elementName].value = "";
var elementName = "UserID_ammend_" + number;
f.elements[elementName].value = "";
}
</script>


<Added>

Typically, you wouldn't declare the variable "elementName" each time like I did. I was copy & paste happy! Just leave off the keyword var on the second and third time we set its value. The code will work just fine like I show, but is more efficient to not declare the variable as a new variable each time just to reassign the value.
Troy Wolf: site expert
Shiny Solutions









CodeToad Experts

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








Recent Forum Threads
•  Re: onload event
•  Active Widgets
•  Re: onmouseover change image and text
•  Line Printer Interface
•  import contacts of msn/yahoo
•  Call windows apps from web apps
•  Re: ASP.NET web controls
•  netscape 6 browser problem
•  Re: Print .doc file from the website using System.Diagnostics.Process


Recent Articles
Communicating with the Database (Using ADO)
MagicGrid
Simple Thumbnail Browsing Solution
Type Anywhere
A Better Moustrap: FmtDate to replace FormatDateTime
ASP.NET Forum Source Code
Internal Search Engine
Javascript Growing Window
Simple date validation
Search engine friendly URLs using ASP.NET (C#.NET)


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2005