Guest hellFOX Posted August 31, 2006 Share Posted August 31, 2006 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 More sharing options...
aspnetguy Posted August 31, 2006 Share Posted August 31, 2006 that won't work but you could pass 'B','C' and use document.getElementById()...you'd have to add an id="C", etc of course Link to comment Share on other sites More sharing options...
tutsamewasa Posted September 4, 2006 Share Posted September 4, 2006 Hi,Two ways, one is add ID attribute and pass the ID with other testbox and get it with getElementbyid.Second is pass the other textbox as document.formname.textboxname.Hope this helps.Good LuckHemendra Singh ShaktawatMindfire Solutionswww.mindfiresolutions.com Link to comment Share on other sites More sharing options...
Jack McKalling Posted September 4, 2006 Share Posted September 4, 2006 <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 More sharing options...
scott100 Posted September 4, 2006 Share Posted September 4, 2006 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now