• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Passing fieldname to Javascript function

alkemyst

No Lifer

I am trying to do something like this in my form:

<input TYPE="text" NAME="bHphone" VALUE="<%= mybPN %>" onFocus="javascript:getIt('bHphone',this)">

my getIt function looks like:

function getIt(fieldname,m){
n=m.name;
//p1=document.forms[0].elements[n]
p1=m
ValidatePhonenumber(fieldname)
}

My code works fine if I refer to document.myFormName.bHphone.value

I don't use javascript alot, but this I need to use on 4 fields on one form and 2 fields on another. Writing 6 separate functions (just changing the formname and fieldnames) would be simple, but redundant.

Anyone know a good way to do this?

Å
 
ahh haven't tested it yet, but that may be the winner.

I was trying to pass the fieldname as a var and doing a:

document.formname.getElementById(fieldname).value.

I didn't paste that line in my original post....

Thanks....also kingtas your link I will check out...they don't have the sourcecode easily viewable and it's friday afterwork now 🙂

I viewed the source though and think I have all the code for it saved.

Å
 
Originally posted by: KB
you can use document.getElementById('bHphone')

Also if I am passing 'bHPhone' as a var to the function say like ******="blah blah('bHPhone',this)" how do I get it in the getElementByID tag...this is where I think I had the right idea already, but my code is not working....I am more used to vbscript/asp.

 
Originally posted by: alkemyst
Originally posted by: KB
you can use document.getElementById('bHphone')

Also if I am passing 'bHPhone' as a var to the function say like ******="blah blah('bHPhone',this)" how do I get it in the getElementByID tag...this is where I think I had the right idea already, but my code is not working....I am more used to vbscript/asp.

Here's an untested example that generally does what you want I think (note that this.id would be "btnOMGHI"):

 
Originally posted by: alkemyst
Thanks....also kingtas your link I will check out...they don't have the sourcecode easily viewable and it's friday afterwork now 🙂

I viewed the source though and think I have all the code for it saved.

Å

You fill out the three text boxes and submit. It will pass what you typed to the next page and also diplay the code.
 
Originally posted by: kingtas
Originally posted by: alkemyst
Thanks....also kingtas your link I will check out...they don't have the sourcecode easily viewable and it's friday afterwork now 🙂

I viewed the source though and think I have all the code for it saved.

Å

You fill out the three text boxes and submit. It will pass what you typed to the next page and also diplay the code.

That's probably just a basic form submit and request.form.
 
That worked Jax...

function getIt(Field,m){
n=m.name;
myField= document.getElementById(Field);
//p1=document.forms[0].elements[n]
p1=m
ValidatePhone()
}

Then I was able to do:
myField.value=pp;


Thanks
 
Back
Top