?
Solved

verify & redirect based on radio selection

Posted on 2003-12-04
12
Medium Priority
?
661 Views
Last Modified: 2012-06-22
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
0
Comment
Question by:deross
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
12 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 9877791
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
 
LVL 33

Expert Comment

by:knightEknight
ID: 9877811
what exactly are you trying to do anyway?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 9877831
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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

Author Comment

by:deross
ID: 9877854
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
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 9877855
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 9878043
yup...
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9878251
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
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 2000 total points
ID: 9878315
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
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 9879688
fritz_the_blank, Where is the form data being sent to?
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9882448
If  the first radial is selected, the form will post to blank.htm; if the second, to main.asp.

Fritz the Blank
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 9888450
onClick="this.form.action =' blank.htm'">
would do it too...
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9888818
>> 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

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question