Page 1 of 1

function call

Posted: Thu Sep 30, 2010 11:09 am
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!

Re: function call

Posted: Thu Sep 30, 2010 1:40 pm
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.