I have a textbox: <input type="text" size="40" name="profilemediaurl" /> and I also have a checkbox with some text behind it: <input type="checkbox" name="autoplay" /> Autoplay? What I want to do is to make the checkbox and "Autoplay?" text appear when the user pasts or types a youtube link into the checkbox. I think "youtube.com" would be a good trigger - when the user types or pastes that the checkbox appears. Would it be possible to make?
perfectly easy to do Put a div with a known id where you want the checkbox etc to appear. Put inside the div. Have a javascript timer set to every 300ms or so that calls a function that examines the contents of the textbox for the characters. This function then sets the innerhtml property of the div to equal the html code you want to display, or to if youtube is not found and resets the checkbox value (this way it clears the checkbox if the link is deleted)
You could also work with the onchange or onkeyup/onkeydown events in the input textbox which will call your testing function
Thanks. This is what I ended up doing: <script type="text/javascript"> function div_appear(){ var str=document.getElementById("mediaurl").value; var pos=str.indexOf("youtube"); if (pos>=0) { document.getElementById("autoplay_div").style.display = ""; }else{ document.getElementById("autoplay_div").style.display = "none"; } } </script> <input type="text" onkeyup="div_appear();" size="40" id="mediaurl" name="mediaurl" /> <div style="display: none" id="autoplay_div"> <input type="checkbox" name="autoplay" /> Autoplay? </div>
Within the event in the input box change "row_appear" to "row_appear()" Then it works for me in Firefox
And dont forget to deselect the checkbox when you hide it - if somebody types in a youtube address, clicks the checkbox then changes their mind and types in a normal address the form will still get sent the checbox value.