Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Page submits return false does not work!

Status
Not open for further replies.

countdrak

Programmer
Jun 20, 2003
358
US
I have 2 simple radio button. Clicking 2nd radio button displays a drop down.

If nothing has been picked from a drop down when radio button 2 has been clicked the page should not be submitted.

I have some code that toggles the display of the drop down depending on which radio button is clicked.

So I have 2 radio buttons like this -

- 1 Radio Button
- 2 Radio Button

and one drop down that only shows up when radio 2 is clicked.

Here is my code -

Code:
	if(document.thisform.radio[1].checked == true)
	{
	
		if(document.thisform.dropdown.selectedIndex == 0 ) 
		{
			alert('Please Pick one value from dropdown')
	
			return false;
		}
	}


For some reason when I click the 2nd radio button twice the drop down disappears and even though the drop has disappeared no value has been clicked but the page still submits.

When I do an alert(document.thisform.dropdown.selectedIndex)the value is 0 and the page submits.

I hope I explained it well. Any help.



 
How are you calling the function that contains the code you posted?

[monkey][snake] <.
 
Put the function on the onsubmit of your form.

like so:

Code:
<form id="blah" method="post" onsubmit="return functionName()">

This will prevent submission.

[monkey][snake] <.
 
Whats the difference between and onclick and onsubmit. I mean I am still returning a false?!
 
You are still returning false, but doing it to the form instead of the button.

Returning false to a button never stops any actions from happening.

[monkey][snake] <.
 
Returning false to a button never stops any actions from happening.

Dont think you are right on that!


Because I always do a return false on a button.

onClick="return checkform();"

on my submit button.

And it works fine. Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top