function call

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
md7dani
Forum Newbie
Posts: 13
Joined: Fri Oct 23, 2009 1:55 am

function call

Post by md7dani »

This is not working:

Code: Select all

<script>
function write_href() {
</script>	
<?php	
//If cars >10
if (cars>10) {
?>	
<script> window.open("bilar.php",'_self'); </script>
<?php } else {?>	
<script>alert("var god invänta svar!");</script>
<?php } //end else?>
<script> } //end function  </script>

<a oNclick="javascript:write_href();"><b>inkommande svar</b></a>
Why it shows an alert box when the page is loaded is strange. It seems like it enters the function without a function call. Have tested with onclick, action and href. They all do the same. Any idea what's wrong here?
thanx!
Last edited by md7dani on Thu Sep 30, 2010 2:30 pm, edited 1 time in total.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: function call

Post by AbraCadaver »

Enters what function? Here is your function and it is not complete. There is nothing inside of it and you don't close it }

[text]<script>
function write_href() {
</script>[/text]

Then later you have some stand-alone code:

[text]<script> window.open("bilar.php",'_self'); </script>[/text]

script tags are not like PHP tags that you can open and close and put partial code anywhere you want. Do a view source on your page.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply