Jump to content

Hiding a div on button click... stuck.


leijae

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.