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? Link to comment https://forums.phpfreaks.com/topic/42609-solved-declaring-functions-inside-html-tags/ 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. Link to comment https://forums.phpfreaks.com/topic/42609-solved-declaring-functions-inside-html-tags/#findComment-206827 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> Link to comment https://forums.phpfreaks.com/topic/42609-solved-declaring-functions-inside-html-tags/#findComment-206867 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 Link to comment https://forums.phpfreaks.com/topic/42609-solved-declaring-functions-inside-html-tags/#findComment-207287 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. Link to comment https://forums.phpfreaks.com/topic/42609-solved-declaring-functions-inside-html-tags/#findComment-207382 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> Link to comment https://forums.phpfreaks.com/topic/42609-solved-declaring-functions-inside-html-tags/#findComment-207557 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.