Jump to content

Making a function


Chocolate570

Recommended Posts

Is it possible to do something like:

<script type="text/javascript">function checkThing(){if (document.getElementById("thing").value=="test"){function alertthing(){alert("Testing. Ok, so this function wouldn't be needed, but is it possible?")}}else{function uhhhya(){alert("Same thing....")}}}</script>

Not urgent, i was just wondering. :)

Link to comment
Share on other sites

I don't think so, if I'm logical. Every function is a standalone, you can't nest them. You may try to define both apart from eachother, and then refer to one inside the other :)Something like this:

function John_Doe() { document.SomeElement.onmouseover=ImageOver}function ImageOver(obj) {obj.style.display = "none"}
Or something :)
Link to comment
Share on other sites

You can use the "new Function()" to create a function that is persistant-or-You can use "var name = function(arg){ stuff to do }

<script type="text/javascript">var myTest = "Test is OK";var dynFunc = null;function mkFunc(tStr){ if(tStr.indexOf('OK') > -1){ myFunction = new Function("str", "alert(str)"); myFunction('Testing String Has \'OK\''); dynFunc = myFunction;  }  else  {  thatFunction = new Function("str", "alert(str)");  thatFunction('Testing does not contain \'OK\'');  dynFunc = thatFunction;  }}mkFunc(myTest);myTest = "Test without..You Know 'ok'";mkFunc(myTest);dynFunc('Called Again');</script>

Thanks,

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...