The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

button which change the background

View previous topic View next topic Go down

button which change the background

Post by sample123 on Fri Jun 21 2013, 14:37

Hello, i have this code



Code:
<input type="button"
value="Pattern1"
onclick="document.body.style.cssText+=';background: red;background-repeat: no-repeat;';">



which change the background from black to red when i click it, but i want when i click this button and background becomes red , i wantremain red and when I recharge the forum.

sample123
New Member

Posts : 13
Reputation : 1
Language : English

Back to top Go down

Re: button which change the background

Post by Ultron's Vision on Fri Jun 21 2013, 15:20

Try setting a cookie with JS. Also, use unobstrusive JavaScript. As in, all click elements are specified in a script and not with onclick="" attributes.

Code:
jQuery(document).ready(function(){

jQuery('input[value="Pattern1"]').click(function(e){

e.preventDefault();
jQuery(document.body).css({
'background-color' : '#ff0000',
'background-repeat' : 'no-repeat'
});

document.cookie = "color=#ff0000";

});

Then, in another JavaScript file.

Code:
jQuery(document).ready(function(){

var myGetCookie = document.cookie.replace(/(?:(?:^|.*;\s*)color\s*\=\s*([^;]*).*$)|^.*$/,"$1");
var testRegex = /#[abcdefABCDEF0-9]{6}/;
if(testRegex.test(myGetCookie)) {
jQuery(document.body).css({
'background-color' : myGetCookie,
'background-repeat' : 'no-repeat'
});
}

});

Hope this helped.


Last edited by Ultron's Vision on Fri Jun 21 2013, 16:50; edited 1 time in total

Ultron's Vision
Forumember

Male Posts : 634
Reputation : 45
Language : English | German | HTML | JavaScript | PHP | C++ | Perl | Java
Location : Vienna, Austria

http://duelacademy.net

Back to top Go down

Re: button which change the background

Post by sample123 on Fri Jun 21 2013, 16:13

it doesn't work :/

sample123
New Member

Posts : 13
Reputation : 1
Language : English

Back to top Go down

Re: button which change the background

Post by Ultron's Vision on Fri Jun 21 2013, 16:51

I edited my code a bit, my RegExp only matched numbers and not hexadecimals, but it should be fixed now.

Ultron's Vision
Forumember

Male Posts : 634
Reputation : 45
Language : English | German | HTML | JavaScript | PHP | C++ | Perl | Java
Location : Vienna, Austria

http://duelacademy.net

Back to top Go down

Re: button which change the background

Post by sample123 on Fri Jun 21 2013, 17:17

what i must write in php ?

doesn't work again :/

sample123
New Member

Posts : 13
Reputation : 1
Language : English

Back to top Go down

Re: button which change the background

Post by Ultron's Vision on Fri Jun 21 2013, 18:32

Who said anything about PHP? O_o
You're using a forumotion-hosted forum, right?
If you can use PHP, this code would be written totally different (and you wouldn't be using a forumotion forum).

Ultron's Vision
Forumember

Male Posts : 634
Reputation : 45
Language : English | German | HTML | JavaScript | PHP | C++ | Perl | Java
Location : Vienna, Austria

http://duelacademy.net

Back to top Go down

Re: button which change the background

Post by sample123 on Fri Jun 21 2013, 18:36

My friend, i want create one button which it can change the color of background etc.

i have created this button with "onclick" but when i do recharge thechanges Leave...


I meant the templates when i said "php".

sample123
New Member

Posts : 13
Reputation : 1
Language : English

Back to top Go down

Re: button which change the background

Post by Ultron's Vision on Fri Jun 21 2013, 19:55

Did you add the JavaScript I provided under Admin Panel -> Modules -> HTML & JavaScript -> JavaScript pages management -> Create a new JavaScript?

Otherwise, I'll provide some more code later on. You might need to enable cookies in your browser.

Ultron's Vision
Forumember

Male Posts : 634
Reputation : 45
Language : English | German | HTML | JavaScript | PHP | C++ | Perl | Java
Location : Vienna, Austria

http://duelacademy.net

Back to top Go down

Re: button which change the background

Post by sample123 on Fri Jun 21 2013, 20:29

i add this code. but nothing.

sample123
New Member

Posts : 13
Reputation : 1
Language : English

Back to top Go down

Re: button which change the background

Post by sample123 on Sat Jun 22 2013, 17:56

Bump

sample123
New Member

Posts : 13
Reputation : 1
Language : English

Back to top Go down

Re: button which change the background

Post by SLGray on Sat Jun 22 2013, 19:54

Please don't double/triple post. Your post need to be separated by 24 hours before bumping, replying or adding more information. Please use the edit button instead!


When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.


SLGray
Administrator
Administrator

Male Posts : 36659
Reputation : 2444
Language : English
Location : United States

http://ztwds.forumotion.com/

Back to top Go down

Re: button which change the background

Post by Ultron's Vision on Sat Jun 22 2013, 20:00

I shall perform some tests with the code and then I'll get back to you, okay?

Ultron's Vision
Forumember

Male Posts : 634
Reputation : 45
Language : English | German | HTML | JavaScript | PHP | C++ | Perl | Java
Location : Vienna, Austria

http://duelacademy.net

Back to top Go down

Re: button which change the background

Post by sample123 on Sat Jun 22 2013, 20:54

ok my friend Smile

sample123
New Member

Posts : 13
Reputation : 1
Language : English

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum