Jump to content

Recommended Posts

I can get it work when I click a radio.

 

// this is my javascript
function hidey(val)
	{
		if(val == 'on' || val === true)
		{
			document.getElementById('a1').checked = true;
			document.getElementById('toshow').style.display = 'block';
			document.getElementById('tohide').style.display = 'none';
		}
		else if(val == 'off' || val === false)
		{
			document.getElementById('a2').checked = true;
			document.getElementById('toshow').style.display = 'none';
		}

	}

//this is my html
<form action=" " method="post">
						This is on <input id="a1" name="kind" type="radio" value="on" checked="checked" onclick="hidey(this.checked);" /><br />
						This is off <input id="a2" name="kind" type="radio" value="on" checked="checked" onclick="hidey(this.checked);" />

 

that works fine, but I can't find anywhere on how to run a function like "hidey" when a button is clicked. Here's my attempt:

 

//this is my javascript
function hidey(val)
	{
		if(val == 'on' || val === true)
		{
			document.getElementById('a1').checked = true;
			document.getElementById('toshow').style.display = 'block';
			document.getElementById('tohide').style.display = 'none';
		}
		else if(val == 'off' || val === false)
		{
			document.getElementById('a2').checked = true;
			document.getElementById('toshow').style.display = 'none';
		}

	}

//this is my html
<input class="button" type="button" value="Continue" onclick="hidey(this.clicked);">

 

i understand that the value isn't on, but that's why i put "true". because when it's clicked, it's true, right?

Link to comment
https://forums.phpfreaks.com/topic/241254-hiding-a-div-on-button-click-stuck/
Share on other sites

 

you're passing an attribute of this that doesn't exist in this element.  You made need to alter your javascript IF statement to include the word "Continue"..

you'll also have to change what you're passing to hidey.

 

like this

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.