Jump to content

Functions not executing - no error msgs


MGLP

Recommended Posts

I have a button with onclick calling a function but nothing happens - no execution, no error msgs, just nothing but every thing else works perfectly.

My code is:

function goBack()
{location.href=\"FT_Tree.php\"; return false;
window.open(location.href); return false;}

<input type=\"Button\" value=\"Home\" class=\"noprint\" style=\"background-color:lightgrey;height:30;width:150\" onclick=\"goBack()\">
 

Link to comment
Share on other sites

All those backslashes are probably going to cause a problem. Other problems are that no code will run after a return statement and the browser will leave the page as soon as you assign a value to location.href.

This button could easily be replace with a link and would not need any Javascript at all.

Link to comment
Share on other sites

I've been using this type of code in loads of files / websites and it works perfectly, e.g. below from another of my files works fine.

About the backslashes, I need to put those in for the quotes. Otherwise I get and error.  If I remember correctly, it's PHP requirement or is it Java?  Don't know but it works with backslash and it doesn't work without backslash.

 

function mycontacts()

{location.href=\"FT_Contacts.php\"; return false;

window.open(location.href); return false;}

 

<input type=\"button\" value=\"Contacts\" onclick=\"mycontacts()\">

 

 

Link to comment
Share on other sites

The reason the JavaScript code works is because it never gets to the second line, the first is always carried out! Does it ever! Open a new window or tab? which is what the second line would do.

IF it is PHP

echo "<input type=\"Button\" value=\"Home\" class=\"noprint\" style=\"background-color:lightgrey;height:30;width:150\" onclick=\"goBack()\">";

OR JavaScript

.innerHTML="<input type=\"Button\" value=\"Home\" class=\"noprint\" style=\"background-color:lightgrey;height:30;width:150\" onclick=\"goBack()\">";

Then yes! these are required, but! If you use single quotes instead of double quotes to encapsulate the html you can avoid the slashes all together.

echo '<input type="Button" value="Home" class="noprint" style="background-color:lightgrey;height:30;width:150" onclick="goBack()">';
innerHTML='<input type="Button" value="Home" class="noprint" style="background-color:lightgrey;height:30;width:150" onclick="goBack()">';

 

Link to comment
Share on other sites

Quote

My original problem was resolved.  I don't know exactly what the problem was but obviously it was some error in my preceding code.  I did some cleaning of my preceding code and then everything was OK.

Concerning the NOT opening of a new window, you are absolutely correct. A new window is not being opened.  So I will amend my code accordingly.

Many thanks for the tip on using the single quote instead of backslash double quote.  I've tried it and it works just fine as you said.

Actually, many thank for everything.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...