Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 2nd May 2016, 11:35 AM   #1
Senior Warrior Member
War Room Member
 
Join Date: 2009
Posts: 1,057
Thanks: 124
Thanked 198 Times in 147 Posts
Default
onpage php in WordPress
Share on: 
fb share twitter share gplus share more share

I'm testing that this button works with a simple function before trying to write a more complex one.It's not working and I don't know what I missed.
Here is the on page code:
Code:
<a role="button" href="?action=check_button" class="add-role">TEST</a>
Here is what I added in the theme function file:
Code:
function check_button()  {
	echo 'This button is being worked on';

}

rhinocl is offline  
Unread 2nd May 2016, 09:55 PM   #2
Active Warrior
 
WebMarketingTool's Avatar
 
Join Date: 2016
Location: Wildwood, GA
Posts: 37
Thanks: 4
Thanked 6 Times in 6 Posts
Default
Re: onpage php in WordPress
Share on: 
fb share twitter share gplus share more share

I'm not big into WordPress but the code that would work on a normal website is below:

<a role="button" href="javascript:check_button()" class="add-role">TEST</a>

And then for the function to change it to alert or something else (like update the content of a div). Below I switched it to an alert:
function check_button() { alert('This button is being worked on'); }

Again, this is just normal html/javascript that will work on any site and not sure how to do it using WordPress features if that is what you are trying to do.
WebMarketingTool is offline  
The Following User Says Thank You to WebMarketingTool For This Useful Post:
Unread 3rd May 2016, 07:46 AM   #3
Senior Warrior Member
War Room Member
 
Join Date: 2009
Posts: 1,057
Thanks: 124
Thanked 198 Times in 147 Posts
Default
Re: onpage php in WordPress
Share on: 
fb share twitter share gplus share more share

I tried the code you gave me and modified the function to read:

Code:
function check_button()  {
	echo 'alert("This button is being worked on")';

}
but still no joy.

rhinocl is offline  
Unread 4th May 2016, 08:57 AM   #4
Active Warrior
 
WebMarketingTool's Avatar
 
Join Date: 2016
Location: Wildwood, GA
Posts: 37
Thanks: 4
Thanked 6 Times in 6 Posts
Default
Re: onpage php in WordPress
Share on: 
fb share twitter share gplus share more share

Originally Posted by rhinocl View Post

I tried the code you gave me and modified the function to read:

Code:
function check_button()  {
    echo 'alert("This button is being worked on")';

}
but still no joy.

The issue is you have:
echo 'alert("This button is being worked on")';
Instead of:
alert("This button is being worked on");

Echo is not used in javascript. Alert gives a popup alert. As an alternative you could use:
document.write("This button is being worked on");

Which would write it at the spot in the page where the code exists, just this is bad practice for several reasons. If you are trying to put in on a page then you would use something like:

document.getElementById("yourid").innerHTML = "This button is being worked on";

And then have an element like a div with the id of yourid like this:
<div id="yourid"></div>

In the example above the javascript code needs to be either beneath the <div> in the file OR it needs to be deferred to not run until after the page has loaded.

Let me know if you have anymore questions/issues.

WebMarketingTool is offline  
The Following User Says Thank You to WebMarketingTool For This Useful Post:
Closed Thread


Bookmarks

Tags
onpage, php, wordpress


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 01:30 PM.