Link to home
Start Free TrialLog in
Avatar of 1desman1
1desman1

asked on

Clear javascript function

Hi Experts,

I have a checkbox that when clicked calls a javascript function, what I want is when it's up-clicked to clear the function to the state it was before it was clicked. I tried the below but no go.

Thanks for reading



function init1() {  
   var elems = document.forms['itemsalelines'].elements;
        if (elems['StartCombo_1'].checked) {
 
     nitobi.initCombo('cmbCustomers1');  
         
	 }
                 }

Open in new window

Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

1desman1,

Your code and question are a little confusing but if you want to have the function clear the event so the next click won't run the function again then you can add the line below to the end of the function.

this.onclick = null;

The other options is to set a global variable to false and then change it to true the first time you go to the function.  The onclick event will have something like the below to test if it was run yet ...

if(!bRun) runFunction();

There is no reason to actually delete the function or to try to clear it.  You just have to make it so it won't run.  :)  Let me know if you have any questions or need more information.

b0lsc0tt
Avatar of 1desman1
1desman1

ASKER

Sorry for the confusion, what happens when the functions fired is a component is launched what I want is when it un-clicked for the component to disappear but it does not and if you click it again another copy appears... make sense?
So instead of unclicked you mean clicked again?  That makes sense.  Don't clear the event then.  Use the global variable method.  When it is checked the first time you change the value (e.g. false -> true).  The function that opens the component can look to see what that value is.  Without details of how to open the component, etc I can't tell you how to close it but this would be a way the one function could do either.

Let me know if you have a question about this.  If you need help with the specifics then please provide more info.

bol
This is a commercial component and the 2 JS files it reads has over 8000 lines of code, so I better not paste it here.

The form I created uses up to 30 lines (order form) and the component needs to be called for each line (as a product number lookup) and takes ages so I created the check box to activate each line as you need the component which works great apart from the above problem... So I guess if this isn't possible is there a smaller component which has input lookup that retrieves 4 or more fields to populate the form? I dont need any back end help just the javascript ajax to search and retrieve.

I'm waaaaaay off topic here, sorry
ASKER CERTIFIED SOLUTION
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks bol, all the component does (ajax) is lookup a database and return a list of matches. It's very customizable but slow loading if you call it more than a few times, hence what I tried to accomplish. I'm just not great at javascript :(

Ill look up your idea
Your welcome!  I'm glad I could help.  Thanks for the grade, the points and the fun question.  Luckily you have us for the Javascript you need help with. :)
bol