MDanz Posted July 19, 2011 Share Posted July 19, 2011 i want if this checkbox is clicked to change the value in the textarea to "Input image url".. the below isn't working though <input type='checkbox' name='image' onclick='if(this.checked) { image(0);}' /> function image(number) { document.outcomes['reason["+number+"]'].value="Input image url"; } <form action='submit.php' method='POST' name='outcomes'> <textarea name='reason[0]'></textarea> </form> Quote Link to comment https://forums.phpfreaks.com/topic/242308-checkbox-onclick-help/ Share on other sites More sharing options...
Adam Posted July 19, 2011 Share Posted July 19, 2011 'reason["+number+"]' To concatenate the variable, you need to close/open the string using a single quote like you originally use to open/close it. Otherwise what you'll end up here with is literally: reason["+number+"]. Also you'd be better off changing the name of the function. "Image" is a default object, and although JS is case-sensitive, it doesn't seem to like you referencing it within the document. You could fix the problem by calling "window.image(0)" - but it would be better to change it to avoid such issues. Quote Link to comment https://forums.phpfreaks.com/topic/242308-checkbox-onclick-help/#findComment-1244501 Share on other sites More sharing options...
reyborn Posted July 20, 2011 Share Posted July 20, 2011 Please make this code as reference, I hope it helps you: <script type="text/javascript"> function ChangeLabel() { if (document.getElementById("image").checked == true) { document.getElementById("textarea").innerHTML = 'Input Image URL'; }else{ document.getElementById("textarea").innerHTML = ''; } } </script> <form> <input type='checkbox' name='image' id="image" onclick="ChangeLabel();" /> <textarea id="textarea"></textarea> </form> Quote Link to comment https://forums.phpfreaks.com/topic/242308-checkbox-onclick-help/#findComment-1244982 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.