ballhogjoni Posted February 26, 2008 Share Posted February 26, 2008 How do I execute two functions on one click: <input type="button" name="Submit" value="CLAIM YOUR KIT" onClick="CancelChat()" onClick="check(form,form.elements.length)"> The problem is that only one fuction executes when I write the code like the above. I need both functions to execute at the same time. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 26, 2008 Share Posted February 26, 2008 It's pretty complicated: <input type="button" name="Submit" value="CLAIM YOUR KIT" onClick="CancelChat();check(form,form.elements.length);"> Quote Link to comment Share on other sites More sharing options...
fenway Posted February 26, 2008 Share Posted February 26, 2008 Not at all... have a wrapper function. Quote Link to comment Share on other sites More sharing options...
GameYin Posted February 26, 2008 Share Posted February 26, 2008 I think he was being sarcastic. Quote Link to comment Share on other sites More sharing options...
fenway Posted February 26, 2008 Share Posted February 26, 2008 I think he was being sarcastic. Sure he was... but his solution still wasn't a wrapper. Quote Link to comment Share on other sites More sharing options...
ballhogjoni Posted February 28, 2008 Author Share Posted February 28, 2008 fenway, I googled wrapper function and couldn't find anything about what you are talking about. Can you send me some more info on the subject, wrapper function. thnx Quote Link to comment Share on other sites More sharing options...
fenway Posted February 28, 2008 Share Posted February 28, 2008 <input type="button" name="Submit" value="CLAIM YOUR KIT" on="return wrapperFunction(this.form)"> <script> fnction wrapperFunction( eForm ) { CancelChat(); return check(eForm,eForm.elements.length); } </script> Quote Link to comment Share on other sites More sharing options...
ballhogjoni Posted March 4, 2008 Author Share Posted March 4, 2008 fenway, I tried that and I get an objected expected error. The problem is that the CancelChat() & check() functions work if they're alone (not being called by the wrapper function). So I don't think its a syntax error within the CancelChat() or check() functions, more along the lines of the function you gave doesn't call the functions correctly. I noticed the "fnction wrapperFunction( eForm ) { " was spelled incorrectly, so I fixed that, but I still get the same error. I am a newb so I could be wrong here. Thanks for your help. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 4, 2008 Share Posted March 4, 2008 Can you please post your current JS code and the code for the html form? You use a global variable 'form', but I don't know where it's being declared. Quote Link to comment Share on other sites More sharing options...
emehrkay Posted March 5, 2008 Share Posted March 5, 2008 This is a simple solution. First remove the inline js. Then create a listener for click of that button. function buttonListener(){ document.getElementById('button id').onclick = wrapper; } function wrapper(){ //your other functions go here } onload = buttonListener; Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 5, 2008 Share Posted March 5, 2008 Yet another solution, and there will be many. But, the problem I think he is having (objected expected error) is that he is loosing the value of a variable somewhere due to variable scope. Quote Link to comment Share on other sites More sharing options...
GameYin Posted March 5, 2008 Share Posted March 5, 2008 For variable scope, variables listen within a function, are local scope and can only be accessed within the function itself, but if you call a variable outside of a function, then it it a global variable and you can access it anywhere. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 5, 2008 Share Posted March 5, 2008 Not true, in Javascript any variable declared globally (outside a function) is accessible from inside a function unless you specifically declare a local version with var. Here is an example: var test1 = 'declare global 1'; var test2 = 'declare global 2'; var test3 = 'declare global 3'; function runTest ( test3 ) { //Variables declared as arguments are always local test1 = 'inside 1'; //Alters the value of the global test1 var test2 = 'inside 2'; //Local variable, global test2 remains unchanged alert("--INSIDE--\ntest1: "+test1+"\ntest2: "+test2+"\ntest3: "+test3); } alert("--BEFORE--\ntest1: "+test1+"\ntest2: "+test2+"\ntest3: "+test3); runTest('argument'); alert("--AFTER--\ntest1: "+test1+"\ntest2: "+test2+"\ntest3: "+test3); Quote Link to comment Share on other sites More sharing options...
GameYin Posted March 6, 2008 Share Posted March 6, 2008 Didn't I just say that? Variables with global scope can be accessed ANYWHERE. Inside functions, outside functions, anywhere. You sorely misread my post. Local scopes can only be used in functions. Quote Link to comment Share on other sites More sharing options...
haku Posted March 6, 2008 Share Posted March 6, 2008 I don't know that that is always true. I declared the following variable outside a function today: var target = document.getElementById("elementName") and was not able to use it inside the function. I had to bring it into the function for it to be usable. Quote Link to comment Share on other sites More sharing options...
GameYin Posted March 6, 2008 Share Posted March 6, 2008 Post the code, in its entirety, I bet I can figure out when you went wrong. I'm 99.99999999999999999999% I am correct and it will take an uber guru with a website to tell me I'm wrong. Quote Link to comment Share on other sites More sharing options...
ballhogjoni Posted March 6, 2008 Author Share Posted March 6, 2008 I figured it out. it was something with my css messing everything up. I do have this problem, read this post: http://www.phpfreaks.com/forums/index.php/topic,185879.0.html Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.