Chocolate570 Posted November 23, 2005 Share Posted November 23, 2005 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 More sharing options...
Jack McKalling Posted November 23, 2005 Share Posted November 23, 2005 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 More sharing options...
Chocolate570 Posted November 23, 2005 Author Share Posted November 23, 2005 What if i wanted to customize a function depending on a user's preferences? Link to comment Share on other sites More sharing options...
Jack McKalling Posted November 23, 2005 Share Posted November 23, 2005 Could you explain more, what do you want to customise for example? Link to comment Share on other sites More sharing options...
Chocolate570 Posted November 23, 2005 Author Share Posted November 23, 2005 See, i'm just asking this out of curiosity, i really don't have any use for it. Link to comment Share on other sites More sharing options...
Jack McKalling Posted November 23, 2005 Share Posted November 23, 2005 All right fair enough Link to comment Share on other sites More sharing options...
hacknsack Posted November 23, 2005 Share Posted November 23, 2005 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 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