Sharkadder Posted June 13, 2008 Share Posted June 13, 2008 EDITsolved, i created another block of code for textarea tags and it works like a charm. the reason i have left all my code in is incase somebody fancies using it and generating their own hints.many thanks to abit of literal thinking by meself lol.see youORIGINAL POSTHi, i have recently been using a hide/show object that displays hint's next to text boxes as your mouse is focused on it. This worked fine for text boxes/radio/checked boxes but it didn't work when using the textarea property within HTML/php forms.The script is created using javascript and works as mentioned above. Currently the script searches for a box within a form starting with <input. So i could have things such as <input type = "text"> <input type = "radio"> etc.Now i have tried to change the script around so that it will include <textarea> but it will not work for me, some of my sample code for the algorithm is shown below.function prepareInputsForHints() { var inputs = document.getElementsByTagName("input") for (var i=0; i<inputs.length; i++){ // test to see if the hint span exists first if (inputs.parentNode.getElementsByTagName("span")[0]) { // the span exists! on focus, show the hint inputs.onfocus = function () { this.parentNode.getElementsByTagName("span")[0].style.display = "inline"; } // when the cursor moves away from the field, hide the hint inputs.onblur = function () { this.parentNode.getElementsByTagName("span")[0].style.display = "none"; } } } // repeat the same tests as above for selects var selects = document.getElementsByTagName("select"); for (var k=0; k<selects.length; k++){ if (selects[k].parentNode.getElementsByTagName("span")[0]) { selects[k].onfocus = function () { this.parentNode.getElementsByTagName("span")[0].style.display = "inline"; } selects[k].onblur = function () { this.parentNode.getElementsByTagName("span")[0].style.display = "none"; } } }}addLoadEvent(prepareInputsForHints);</script>Now half of that coding you do not need to know, as far as i am aware the only part what needs sorting is this line: var inputs = document.getElementsByTagName("input")As you can see by the line above, it searches for tags with the name "input", i know you might be thinking well why not just write ("input","textarea") or try writing ("input" || "textarea"), well the truth is i have and it doesn't seem to like it. Does this mean i am going to have to do a whole new block for textarea as well? If that is the case then it may look odd, as the code only displays one hint for whatever form element the mouse is focused on. So if i do a whole new block for textarea, it may display 2, one for input tags and one for textarea tags which isn't what i want.I hope somebody can understand what i am asking. I also tried ("input") || ("textarea") and still no joy.thanks Link to comment Share on other sites More sharing options...
Ingolme Posted June 13, 2008 Share Posted June 13, 2008 You have to make another block of code for the textarea. getElementsByTagName only gets one type of tag. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.