There is a code

<html> <head> <script type="text/javascript"> function delPost($num) { x=confirm("Вы действительно хотите удалить пост?"); if (x==true) { window.location.href = линк } } } </script> </head> <body> <input type="button" onclick="javascript: delPost(1)" value="тест"></input> </body> 

However, when the button is pressed, nothing happens, although it should pop up a confirmation window.

What am I doing wrong?

  • Count the number of closing braces. - barber
  • I advise you to abandon onclick in js, in favor of jquery, in order not to fence unnecessary fences in the html itself. This is worth considering if you are looking for innovation and modern development methods. - Ishutinov Dmitry

3 answers 3

Count how many you have open {and closed}.

What is this javascript:?

There is a great tool-firebug

  • damn, for sure, I really went crazy :) I got used to the fact that php pokes a finger at such errors))) I read that javascript: is an indication of the protocol through which the action is performed. Or it is not necessary to specify? - Garfild
  • optional, put firebug or at least googlechrome, there it is already embedded - thunder
  • I have some chrome. IEs will be fine? - Garfild
  • with this script - yes) - thunder
  • with this - in the sense of javascript:? )) - Garfild

What else $num ??? even read the syntax .. And more superfluous} at the end

 <html> <head> </head> <body> <input type="button" onclick="delPost(1)" value="тест"></input> <script> function delPost(num) { x=confirm("Вы действительно хотите удалить пост?"); if (x==true) { window.location.href = "линк"; } } </script>​ </body> 

    Javascript javascript: must be specified at the beginning if javascript is used. For example, <a href="javascript:delPost(1);">[X]</a> .