Jump to content

Javascript Function


Guest hellFOX

Recommended Posts

Guest hellFOX

hi all,given the following code :<input type="text" name="A" onclick="FuncA(this)"><input type="text" name="B" onclick="FuncA(this)"><input type="text" name="C" onclick="FuncA(this)">if any of the textbox was clicked the FuncA() will be executed, and the textbox will be submitted as the parameter.now what if for example instead of passing the textbox itself, i want to pass the other textbox instead as the parameter for the function.<input type="text" name="A" onclick="FuncA(B,C)"> <-- textbox B,C are passed<input type="text" name="B" onclick="FuncA(this)"><input type="text" name="C" onclick="FuncA(this)">is this possible , or any workaround suggestions, will dothanks people..

Link to comment
Share on other sites

<input type="text" name="A" onclick="FuncA(this.form.elements['B'])"><input type="text" name="B" onclick="FuncA(this)"><input type="text" name="C" onclick="FuncA(this)">
The "this" passes the calling element, the "form" object of "this" refers to the form element this field is in, and .elements[] is an array of elements of that very form, of name attributes. I hope this helps you. :)
Link to comment
Share on other sites

that won't work but you could pass 'B','C' and use document.getElementById()...
I was thinking the same but out of curiosity decided to give it a try, it turns out that this does work. If you pass FuncA() with the parameters A,B or C it will find the element on the page with that name/id. I have tried this will firefox etc and it's all good, in the example i have alerted the value of the element passed.
<html><head><script>function FuncA(val1,val2){alert("Value 1="+val1.value+" ; Value 2="+val2.value);}</script></head><body><form><input type="text" name="A" onclick="FuncA(B,C)"><input type="text" name="B" onclick="FuncA(A,C)"><input type="text" name="C" onclick="FuncA(A,B)"></form></body>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...