SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
-
Dec 17, 2007, 14:54 #1
- Join Date
- Apr 2004
- Location
- Boston
- Posts
- 482
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
javascript getElementByID() to form value
Hello,
I am trying to implement a color picker for my users to choose their own custom background colors. I have an ajax color picker that works great but I am having issues passing the picked HEX value to my form. I am also using PHP.
Here is my javascript.
HTML Code:<div id="plugHEX" onmousedown="stop=0; setTimeout('stop=1',100);">FFFFFF</div>
However I need to pass that value through a form so that I can update my DB for the user who picked.
My form field should look something like this:
HTML Code:<input type="hidden" name="color" id="plugHEX" value="VALUE FROM PICKER">
Thanks
-
Dec 17, 2007, 17:52 #2
- Join Date
- Sep 2005
- Location
- Tanzania
- Posts
- 4,662
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
getElementById is case sensitive, so for starters you have written it wrong. Also, don't use inline javascript (in the HTML). Put it in the HEAD.
Code Javascript:window.onload = function() { document.getElementById('plugHEX').onmousedown = function() { document.getElementById('pickedValue').value = this.firstChild.nodeValue; } }
HTML Code:<div id="plugHEX">FFFFFF</div> <input type="hidden" name="color" id="pickedValue" value="">
-
Dec 17, 2007, 19:17 #3
- Join Date
- Apr 2004
- Location
- Boston
- Posts
- 482
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thank you I will try it, I didn't write the ajax code, i found a free plugin that I am trying to implement with my PHP code. I got it to work well enough with some design changes but I still need to pass the hex value through the form to update with the rest of the info on the page.
Bookmarks