Jump to content
Background Color:

<select id="BGColor">

<option value="#FFFFFF">White</option>

<option value="#000000">Black</option>

<option value="#FF0000">Red</option>

<option value="#008800">Green</option>

<option value="#0000FF">Blue</option>

<option value="#F08080">Light Coral</option>

<option value="#ADD8E6">Light Blue</option>

<option value="#90EE90">Light Green</option>

</select>

Hey guys how would I give a user the option to edit the style of a page with javascript? so if I had a select list like this ^^ how would I make javascript change the style depending on what they picked? Thanks for any help!

Link to comment
https://linustechtips.com/topic/992213-how-to-edit-css-with-javascript/
Share on other sites

Link to post
Share on other sites

Keep in mind Java and Javascript are different things and some might get triggered by not calling it by the right name.

 

Either way, this might help:

https://www.w3schools.com/js/js_htmldom_css.asp

Not sure how exactly you want to implement it, but you could add like 8 buttons, each corresponding to a color and when a button is pressed you call a function which changes everything that needs to be changed.

You could make 8 different functions, but it would be better to use parameters: https://www.w3schools.com/js/js_function_parameters.asp

Basically you call a function and give some values together with it that can be used (e.g. you give your button for making the website blue the color code for your desired shade of blue and thus when you call the function you automatically have the correct colorcode in the function).

 

Not sure how serious you are taking this website, but you can consider saving the user's color preference in a cookie so when they revisit your website (or go to another page on the website), it remembers their color choice.

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to post
Share on other sites

13 minutes ago, Minibois said:

Keep in mind Java and Javascript are different things and some might get triggered by not calling it by the right name.

 

Either way, this might help:

https://www.w3schools.com/js/js_htmldom_css.asp

Not sure how exactly you want to implement it, but you could add like 8 buttons, each corresponding to a color and when a button is pressed you call a function which changes everything that needs to be changed.

You could make 8 different functions, but it would be better to use parameters: https://www.w3schools.com/js/js_function_parameters.asp

Basically you call a function and give some values together with it that can be used (e.g. you give your button for making the website blue the color code for your desired shade of blue and thus when you call the function you automatically have the correct colorcode in the function).

 

Not sure how serious you are taking this website, but you can consider saving the user's color preference in a cookie so when they revisit your website (or go to another page on the website), it remembers their color choice.

I fixed the title sorry didn't realize thanks for showing me, and here is a pic of the site I created I'm just trying to learn with this website which method would be best? https://gyazo.com/761d382ee8d752a427acac69d67d318c

Link to post
Share on other sites

3 minutes ago, Cookiecrumbles222 said:

I fixed the title sorry didn't realize thanks for showing me, and here is a pic of the site I created I'm just trying to learn with this website which method would be best? https://gyazo.com/761d382ee8d752a427acac69d67d318c

When the format button is pressed, the function you are calling after that (for example your 'formatThePage' function) should get a couple of parameters with it; the foreground color, background color, font+font size+bold+italic+underline and should make a webpage based upon that.

I am not super well educated in the whole php thing (what you would use for the cookies I believe) but I am sure you can pass this info to there too.

 

Anyways, your calling the function will probably look something like this:

"formatThePage(bgColor, fgColor, fontName, fontSize, boldText,italicText, underlineText);" and your function should take these values and make the webpage according to that.

 

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to post
Share on other sites

  • 5 months later...

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

×