|
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.
|
|
|
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.
|
|
|
|
|
|
|
|
|
|