Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

modifying form-field-name with a function parameter

Status
Not open for further replies.

keyman2007

Technical User
May 31, 2007
3
CA
Hi, all...

I am trying to do something that seems pretty elementary, but I am stumped.

I want to do the same JS edit on a number of form fields, so rather than code the edit in 10 locations, I wanted to make a function that takes the form-field-name as a parameter (qq) to do the edit. An idea like the following, except the code doesn't work.

(I know there are other ways to do these edits, but I am asking how to replace the segment in the document field-name with a variable):
==================================
test("lastname") // call the function, passing field-name
if (pp == 1) {
alert("No periods allowed in this field")
return false
}

test("firsname") //call the function, passing field-name
if (pp == 1) {
alert("No periods allowed in this field")
return false
}

function test(qq) {
var pp = 0
for (var i=0; i <= document.idform.qq.value.length; i++) {
if (document.idform.qq.value.charAt(i) == "."
{
pp=1;
}
}
}
[/color red]
==================================
 
Dan - thanks, that sorted it! Great. I'm not quite clear what the problem was, though...

Thanks again everybody for your assistance

===Toby===
 
21524,

Perhaps you should start a new thread for your question, and also post the form code you have, including the elements, and describe what is being passed into the function.

Toby,

As previously mentioned, if you use document.write AFTER the page has loaded, it wipes the contents of the page (which includes JavaScript variables and functions - thus rendering them no longer available).

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hi Dan - yes, I saw that thanks - I just don't understand the rationale behind it or why it happens!

===Toby===
 
Hi Dan,

sorry about that. Next time onwards I will start new thred,

I have got solution for that. It was spaces in the value which was creating problem.

Thanks,
Preeti
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top