Forum:Error catching Hex code colours AND X11 colours

I'm trying to create a template with customizable colours using something along the lines of:

style="background-color:;"

However, I can only seem to manage the user choosing an X11 colour (Green, SandyBrown, PaleTurquoise etc) OR a hex code (#339933, #fff etc).

How can I allow the user to choose the variable 'colour' (in the above instance) as either, without the # symbol screwing with the code?

So far I've been using X11, or can manage Hex by making the code #, but that stops X11 being possible.

Thanks OllieMartin 18:36, August 1, 2010 (UTC)


 * Parameters with # symbols usually work just fine, as proven by this template I created (which includes this code:  

), so I truly don't understand why it wouldn't work for you. BramTalk/IGW 18:58, August 1, 2010 (UTC)


 * And that template allows users to enter colour = #333333 or Green? Hmmmm, must investigate. Thanks....OllieMartin 19:06, August 1, 2010 (UTC)
 * Nope definitely not working. The only difference I can see is that you're using the code for a table border whereas I'm using it for a background, but I can't see why that would make a difference! OllieMartin 19:10, August 1, 2010 (UTC)


 * It does work for the border. There's no reason why it wouldn't work for setting the background color the same way. Parameters aren't that smart (or dumb). Do you have a link to the template page you're working on? BramTalk/IGW 19:14, August 1, 2010 (UTC)


 * Yea, that's what I thought, it appears to be picking the # up as a number code:
 * number one
 * number two
 * Link is: Navbox. Feel free to mess about, the site doesn't appear to have any visitors...yet! Thanks OllieMartin 19:18, August 1, 2010 (UTC)


 * I did a few tests and it looks like the problem is the wiki table markup language you used to construct your template. I created this test template with the colour parameter CSS style property string you posted here used in an HTML table context, a Div context and a wiki table markup context. If you check out the two examples I filled out at the Sandbox, you'll see the HTML table and div work with both X11 and hex codes, but the wiki markup table only works works with X11. Although wiki table markup usually works well with CSS style properties and in templates, it isn't perfect I guess.
 * One solution would be to reconstruct your template using, , , etc. , instead of wiki markup language but maybe someone else has a better/easier idea? BramTalk/IGW 20:09, August 1, 2010 (UTC)


 * Thanks for looking anyway. I did suspect it might be that as your example was built in HTML. Might have a look at the conversion job next time I've got some free time. I can't imagine I've the first person to have this issue...surely? OllieMartin 22:20, August 1, 2010 (UTC)