Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Dynamic return url

Posted on 2003-10-27
10
Medium Priority
?
310 Views
Last Modified: 2008-02-01
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>
0
Comment
Question by:byteslinger
[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
  • 2
  • 2
  • +2
10 Comments
 
LVL 25

Expert Comment

by:devic
ID: 9631022
byteslinger,

1. name cannot begin with number
0
 
LVL 3

Expert Comment

by:superslamwich
ID: 9631050

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
 
LVL 3

Expert Comment

by:superslamwich
ID: 9631058
and I agree with devic, you do need to change the name and have it start with a letter not a number
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 25

Expert Comment

by:devic
ID: 9631081
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
 
LVL 3

Expert Comment

by:superslamwich
ID: 9631127
All?  My bad, I thought it was just one of them.
0
 

Author Comment

by:byteslinger
ID: 9635992
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
 
LVL 3

Expert Comment

by:superslamwich
ID: 9637077
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
 

Author Comment

by:byteslinger
ID: 9637851
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
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10346045
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
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 10377131
PAQed, with points refunded (125)

Computer101
E-E Admin
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

604 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