1

I am trying to use an HTML form to submit a color value.

<form>
Font color:<br>
    <input type="color" name="colorInput">
    <input type="submit" value="Submit">
</form>

I then want to have the color value to replace another value for font color in CSS:

textarea {color: #fff;}

I'm new and have little experience with coding.

Thank you in advance!

1 Answer 1

2

textarea {color: #fff;}
<form>
Font color:<br>
    <input type="color" name="colorInput">
    <input type="submit" value="Submit" onsubmit="return false"  onclick="document.getElementById('ss').style.color=colorInput.value; console.log(colorInput.value)">
</form>


<textarea id="ss"rows="10" cols="30">test</textarea>

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for your reply! I tried the code, and it worked. However, the page refreshes when I press 'Submit'. Is there any way around this? Thank you again!
@RomeroSomero Ok you can use event.preventDefault(); or return false to not refresh page. I've edited it.
I used event.preventDefault() and it worked! Thank you very much for all your help!
How to get the fiddle link?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.