Dynamic return url

I'm trying to add some conditionals to a form in which I have little control over naming conventions, etc.

Essentially I want a dynamic confirmation page redirect upon form submit. If the first four options in the "00N00000005kB6x" select box are selected it should go to Yahoo, if the last three options are selected it should go to Google. All named elements should remain as is, however, as well as the form action.

Can someone set this up so that the "retURL" hidden field is a dynamic value depending upon what is selected in the "00N00000005kB6x" select box?


<html>
<head>
<title></title>

<script language="JavaScript"><!--
function validateForm(form) {
      if ((theForm.first.value == "") || (theForm.lastn.value == "") || (theForm.email.value == "")) {
      alert("Please fill in all required fields.");
      return false;
      } else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(theForm.email.value)){
            return true;
      } else {
            alert("Invalid E-mail Address! Please re-enter.")
            return false;
      }
}
// --></script>

</head>

<body>

<form action="http://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" name="theForm" method="POST" onSubmit="return validateForm()">

<input type=hidden name="retURL" value="https://www.yahoo.com">
<table>
<tr><td align=right>First:<td><td><input type="text" name="first" maxlength=40 style="width:180px;"></td></tr>
<tr><td align=right> Last:<td><td><input type="text" name="lastn" maxlength=40 style="width:180px;"></td></tr>
<tr><td align=right>Email:<td><td><input type="text" name="email" maxlength=80 style="width:180px;"></td></tr>
</table>
<select multiple name="00N00000005kB6x" size="7" style="width:500px">
<option value="one" selected>one</option>
<option value="two">two
<option value="three">three
<option value="four">four
<option value="five">five
<option value="six">six
<option value="seven">seven
</select>

<p>

<input type="submit" name="submit" value="Register">
</body>

</html>
byteslingerAsked:
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.

devicCommented:
byteslinger,

1. name cannot begin with number
0
superslamwichCommented:

function valsel(sel)  {
  if(sel.selectedIndex < 4)  sel.form.retURL.value = "http://www.yahoo.com"
  if(sel.selectedIndex > 3)  sel.form.retURL.value = "http://www.google.com"
}

Then in the select put:

onChange='valsel(this)'

{Slam}
0
superslamwichCommented:
and I agree with devic, you do need to change the name and have it start with a letter not a number
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.

devicCommented:
oops, and i understood that must all first four options and all last three options be selected....
===========================
<html>
<head>
<title></title>

<script language="JavaScript"><!--
function validateForm(form)
{
      checkSelect(form);
      //for test return false
      return false;
    if ((theForm.first.value == "") || (theForm.lastn.value == "") || (theForm.email.value == "")) {
    alert("Please fill in all required fields.");
    return false;
    } else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(theForm.email.value)){
         return true;
    } else {
         alert("Invalid E-mail Address! Please re-enter.")
         return false;
    }
}
function checkSelect(form)
{
      var objsel=form.a00N00000005kB6x

            if((objsel[0].selected)&&(objsel[1].selected)&&(objsel[2].selected)&&(objsel[3].selected))
            {
                  form.retURL.value="http://www.yahoo.com"
            }
            else if((objsel[4].selected)&&(objsel[5].selected)&&(objsel[6].selected))
            {
                  form.retURL.value="http://www.google.com"
            }
            else
            {
                  //what should be else???
            }
}
// --></script>

</head>

<body>

<form action="http://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" name="theForm" method="POST" onSubmit="return validateForm(this)">

<input type=text name="retURL" value="http://www.msn.com">
<table>
<tr><td align=right>First:<td><td><input type="text" name="first" maxlength=40 style="width:180px;"></td></tr>
<tr><td align=right> Last:<td><td><input type="text" name="lastn" maxlength=40 style="width:180px;"></td></tr>
<tr><td align=right>Email:<td><td><input type="text" name="email" maxlength=80 style="width:180px;"></td></tr>
</table>
<select multiple name="a00N00000005kB6x" size="7" style="width:500px">
<option value="one" selected>one</option>
<option value="two">two
<option value="three">three
<option value="four">four
<option value="five">five
<option value="six">six
<option value="seven">seven
</select>

<p>

<input type="submit" name="submit" value="Register">
</body>

</html>
0
superslamwichCommented:
All?  My bad, I thought it was just one of them.
0
byteslingerAuthor Commented:
Hi there...guys, thanks for the help. Unfortunately, I don't have control over the naming of the select box, as that value is assigned by the tracking app we're using (salesforce). This was the dilemma for me. I was hoping that a workaround could be provided using the variables I provided in my example...?
0
superslamwichCommented:
Well, If you change the value onChange in the select like in my script, you don't need to worry about the name as far as the script goes.  However there may be other problems.

BTW - here is my script if you want it to be ALL of the first 4 or ALL of the last 3:

function valsel(sel)  {
 if(sel[0].selected && sel[1].selected && sel[2].selected && sel[3].selected)  sel.form.retURL.value = "http://www.yahoo.com"
 if(sel[4].selected && sel[5].selected && sel[6].selected)  sel.form.retURL.value = "http://www.google.com"
}

and call it the same way
0
byteslingerAuthor Commented:
Thanks guys, I figured out a solution for the problem, but in a different way. Here's what I did:

<script language="javascript">
function classOption(text, value, confirmPage) {
      this.option = new Option(text, value);
      this.confirmPage = confirmPage;
}
var options = new Array();
options.push(new classOption("Blah1", "Blah1", "http://www.yahoo.com"));
options.push(new classOption("Blah2", "Blah2", "http://www.yahoo.com"));
options.push(new classOption("Blah3", "Blah3", "http://www.yahoo.com"));
options.push(new classOption("Blah4", "Blah4", "http://www.yahoo.com"));
options.push(new classOption("Blah5", "Blah5", "http://www.google.com"));
options.push(new classOption("Blah6", "Blah6", "http://www.google.com"));
options.push(new classOption("Blah7", "Blah7", "http://www.google.com"));
function setUpOptions() {
      document.theForm.returnIt.options.length = options.length;
      for (var i = 0; i < options.length; i++) {
            document.theForm.returnIt.options[i] = options[i].option;
      }
      document.theForm.retURL.value = options[0].confirmPage;
}
function getconfirmPage(idx) {
      return options[idx].confirmPage;
}
</script>
<body onload="setUpOptions();">
<form name="theForm">
<table border="0">
<tr>
<td>
<select id="returnIt" name="00N00000005kB6x" onChange="this.form.retURL.value=getconfirmPage(this.selectedIndex);">
</select>
</td>
<td><input name="retURL" type="text" value=""></td>
</tr>
</table>
</form>
</body>

Does the trick:)
0
jaysolomonCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

PAQ with points refunded

Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer
0
Computer101Commented:
PAQed, with points refunded (125)

Computer101
E-E Admin
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
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.