verify & redirect based on radio selection

Here is my code:

<script language=JavaScript>
function checkForm(theForm)
{
if (theForm.results.value=="")
{
alert("Please make a choice.");
return (false);
}
return (true);
}
</script>


<script language = "JavaScript">
function deturl()
{
if (document.forms[0].option2[0].checked)
window.location.replace("blank.htm");
else
window.location.replace("main.asp");
}
</script>


<FORM name="MForm" METHOD="POST" onsubmit = "return checkForm(this); deturl()">


<input type=text name="results">


<INPUT TYPE="radio" NAME="option2" VALUE="value1" onClick='MForm.results.value="match";'>
<INPUT TYPE="radio" NAME="option2" VALUE="value2" onClick='MForm.results.value="nomatch";'>


<INPUT type=submit value ="Submit">

The validation works fine but it does not redirect.

Thanks,

Don
derossAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

knightEknightCommented:
You can't call anything after a return statement:

   onsubmit="return checkForm(this); deturl();"

will not work because the method stops at return.

You can try:

   onsubmit="var rc=checkForm(this); if (rc)deturl(); return rc;"
0
knightEknightCommented:
what exactly are you trying to do anyway?
0
Michel PlungjanIT ExpertCommented:
1. what is the point of filling something in and then replace a page instead
2.


<FORM >
<INPUT TYPE="radio" NAME="option2" VALUE="value1" onClick="window.location.replace('blank.htm')">
<INPUT TYPE="radio" NAME="option2" VALUE="value2" onClick="window.location.replace('main.asp')">
</form>
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

derossAuthor Commented:
A user has two radio buttons to select from plus a submit button.

First, I want to make shure the user has selected one of the two radio buttons before submitting.

Second, depending on which of the two radio buttons the user selected, they will be directed to 'page1.htm' (radio button #1) or page2.htm' (radio button #2).

Don
0
GwynforWebCommented:
when the form is submittd the page that is the action property of the form is opened ie where the form data is sent to. The redirects must take place in the asp page that the data is being sent to
0
Michel PlungjanIT ExpertCommented:
yup...
0
fritz_the_blankCommented:
I am not sure that this is relevant, but if you use the location.replace, all of your form data will be lost. So, replace may not be the way to go.

I would suggest instead that you:

1) validate that a selection has been made
2) based on the selection, dynamically change the action attribute of the form

Fritz the Blank
0
fritz_the_blankCommented:
Something like this perhaps?

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<SCRIPT LANGUAGE=javascript>
<!--
function checkRadioControl(strFieldName,strMessage){
      var objFormField = document.forms[0].elements[strFieldName]
      intControlLength = objFormField.length
      bolSelected = false;
      for (i=0;i<intControlLength;i++){
            if(objFormField[i].checked){
                        bolSelected = true;
                        break;
            }
      }      
      if(! bolSelected){
            alert("Please select one option for " + strMessage + "!");
            return false;
      }else{
            return true;
      }
}

function checkForm(){
      if(checkRadioControl('option2','Value')){
            return true;
      }
      return false;
}
      
      
//-->
</SCRIPT>


</HEAD>
<BODY>
<FORM name="MForm" METHOD="POST" onsubmit = "return checkForm(this)">
<input type=text name="results">
<INPUT TYPE="radio" NAME="option2" VALUE="value1" onClick="document.forms[0].action =' blank.htm'">
<INPUT TYPE="radio" NAME="option2" VALUE="value2" onClick=document.forms[0].action =' main.asp'">
<INPUT type=submit value ="Submit">

</BODY>
</HTML>


Fritz the Blank
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GwynforWebCommented:
fritz_the_blank, Where is the form data being sent to?
0
fritz_the_blankCommented:
If  the first radial is selected, the form will post to blank.htm; if the second, to main.asp.

Fritz the Blank
0
Michel PlungjanIT ExpertCommented:
onClick="this.form.action =' blank.htm'">
would do it too...
0
fritz_the_blankCommented:
>> onClick="this.form.action =' blank.htm'" <<

Ah, but that makes too much sense!

I'll remember to do it that way next time, Michel.

Fritz the Blank
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.