Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/242308-checkbox-onclick-help/
Share on other sites

'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.

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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.