frikus Posted March 14, 2007 Share Posted March 14, 2007 Is it possible to declare an event handler function directly inside HTML tags? Something like this: <select onchange="function() {var $ok='ok'; alert($ok); }"> <option value="1">1</option> <option value="2">2</option> </select> It doesn't work, is there any other way to do this? Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted March 14, 2007 Share Posted March 14, 2007 You can declare the function for onchange= but the vars and alert need to be in the script I believe. Quote Link to comment Share on other sites More sharing options...
jitesh Posted March 14, 2007 Share Posted March 14, 2007 $ok is php variable. Now check this <select onchange="function() {var ok='ok'; alert(ok); }"> <option value="1">1</option> <option value="2">2</option> </select> Quote Link to comment Share on other sites More sharing options...
frikus Posted March 14, 2007 Author Share Posted March 14, 2007 no success, i think it's impossible Quote Link to comment Share on other sites More sharing options...
fenway Posted March 14, 2007 Share Posted March 14, 2007 Why the function()? It already "is" a function. Quote Link to comment Share on other sites More sharing options...
frikus Posted March 14, 2007 Author Share Posted March 14, 2007 Thanks! I didn't know that it could be a function already, JavaScript is really a tricky language. For everyone who is interested, it works correctly in this way: <select onchange="var ok='ok'; alert(ok);"> <option value="1">1</option> <option value="2">2</option> </select> 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.