Solved

Dynamic return url

Posted on 2003-10-27
10
301 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
  • 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jQuery delay animation 3 30
Scroll 5 news at a time. 4 28
Getting Random number with min and max value. 2 28
Not allowed to load local recource. 4 14
This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
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…

803 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