Hi I have found the script below on this forum (http://www.codingforums.com/showthre...to_threadtools) and I´m using a form generated by a CRM system which I don´t have control over the way it names the form fields so I ended up with fields such as id="00N30000002PCO8" name="00N30000002PCO8".
Since I read JavaScript doesn´t allow variables starting with numbers I wonder if there is a way of "making" it accept the variables starting with numbers or if there is a way of modifying the script below in order to read another tag such as alt="test" which I could use it as a controlled variable.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy for Windows (vers 1 June 2005), see www.w3.org">
<meta http-equiv="Content-Language" content="en-au">
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>User info</title>
<script language="JavaScript" type="text/javascript">
<!--
function SymError()
{
return true;
}
window.onerror = SymError;
var SymRealWinOpen = window.open;
function SymWinOpen(url, name, attributes)
{
return (new Object());
}
window.open = SymWinOpen;
//-->
</script>
<script language="JavaScript" type="text/javascript">
<!-- Begin
function getParams() {
var idx = document.URL.indexOf('?');
if (idx != -1) {
var tempParams = new Object();
var pairs = document.URL.substring(idx+1,document.URL.length).split('&');
for (var i=0; i<pairs.length; i++) {
nameVal = pairs[i].split('=');
tempParams[nameVal[0]] = nameVal[1];
}
return tempParams;
}
}
var params = getParams();
// End -->
</script>
</head>
<body>
<form method="post" name="myForm" action="--WEBBOT-SELF--" id="myForm">
<!--webbot bot="SaveResults" U-File="C:\TEST\Tutorial\Emails sent\_private\form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->
<p> Email:
<input type="text" name="email" size="20">
</p>
<p> Account:
<input type="text" name="cid" size="20">
</p>
<p>
<input type="submit" value="Submit" name="B1">
<input type="reset" value="Reset" name="B2">
</p>
</form>
<script language="JavaScript" type="text/javascript">
<!-- Begin
pvName = unescape(params["email"]);
if (pvName) document.myForm.email.value = pvName;
pvName = unescape(params["cid"]);
if (pvName) document.myForm.cid.value = pvName;
// End -->
</script>
<script language="JavaScript" type="text/javascript">
<!--
var SymRealOnLoad;
var SymRealOnUnload;
function SymOnUnload()
{
window.open = SymWinOpen;
if(SymRealOnUnload != null)
SymRealOnUnload();
}
function SymOnLoad()
{
if(SymRealOnLoad != null)
SymRealOnLoad();
window.open = SymRealWinOpen;
SymRealOnUnload = window.onunload;
window.onunload = SymOnUnload;
}
SymRealOnLoad = window.onload;
window.onload = SymOnLoad;
//-->
</script>
</body>
</html>
I have tried the following but for some reason it does not work. It seems like the script only reads the "id" or "name" tags which are the ones I can´t modify.
Code:
pvAlt = unescape(params["protocolo"]);
if (pvAlt) document.SalesForce.test.value = pvAlt;
It should prepend an 'x' to any parameter name that starts with a digit. Then you can adapt your subsequent code to expect that.
Yes, but as I understand it the CRM system will not then recognise the name.
Otherwise the OP could simply change the names of the variables and/or tokens by hand to anything he wants.
Yes, but as I understand it the CRM system will not then recognise the name.
Otherwise the OP could simply change the names of the variables and/or tokens by hand to anything he wants.
Hi, Thank you all for your comments,
Yes, Philip M is right, I cannot change the ID and Name variables in the form field so I was thinking about changing the code so it could identify the field from a different tag other than "ID" or "Name" such as Alt="test", if the script could look for the tag "Alt" as an Identifier then I would have a way to control the variable names.
As I mentioned above I have tried the following, which should be enough to solve the problem of variables starting with numbers but it seems the script does not look for the "Alt" tag. Since I´m just a curious JavaScript user I don´t know how to make the script look for the "Alt" tag, it seems it only recognizes ID and Name tags, so I really need some help. Thanks.
Code:
pvAlt = unescape(params["protocolo"]);
if (pvAlt) document.SalesForce.test.value = pvAlt;
I am sorry say that it cannot be done. I am surprised that your CRM system generates ids which start with a digit and are thus invalid.
Hi Philip M, I really appreciate your time and effort.
I guess I will have to try a language that accepts variables starting with numbers. Hopefully PHP. I found it odd that this was the only script I could find that would do this simple task.
No problem - glad to assist.
But PHP is exactly like Javascript. Variable names follow the same rules as other labels in PHP. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.
Here is an idea which may or may not work. Use ArtyEffem's script to prepend an x to all variables and tags, then onsubmit run another script to delete the x again and restore them to their original all-numeric names.
All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
No problem - glad to assist.
But PHP is exactly like Javascript. Variable names follow the same rules as other labels in PHP. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.
Here is an idea which may or may not work. Use ArtyEffem's script to prepend an x to all variables and tags, then onsubmit run another script to delete the x again and restore them to their original all-numeric names.
All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
Hi Philip M, great idea, I will modify the script according ArtyEffem´s suggestion but unfortunatly I´m not a coder so I have no idea how to make the onsubmit action you suggested. I will google around to see if I can learn it but any help will be very handy.
<form ... onsubmit = "killx()";
function killx () {
for (var i=0; i < pairs.length; i ++) {
nameVal = pairs[i].split('=');
if (nameVal[0].match/^x/) {
nameVal[0] = nameVal[0].replace(/^x/, "");
}
}
}
Hi,
Thanks Philip M, I could not make it work , sorry, so I decided not to use Arty Effem's script and set the x manually on one field "name" hoping the "killx" function would do it's job but my CRM system is not receiving the info so I guess the "x" is not being removed. It recieves the info correctly when I don't use the script.
I wonder if you could take a look at the whole thing and see if there is still any hope..
Hi,
Thanks Philip M, I could not make it work , sorry, so I decided not to use Arty Effem's script and set the x manually on one field "name" hoping the "killx" function would do it's job but my CRM system is not receiving the info so I guess the "x" is not being removed. It recieves the info correctly when I don't use the script.
I wonder if you could take a look at the whole thing and see if there is still any hope..
killx needs to address the form elements; use it like this:
Code:
function killx(theForm)
{
for (var i=0, elems=theForm.elements; i < elems.length; i ++)
elems[i].name = elems[i].name.replace(/^x/, "");
}
and call it: onsubmit="killx(this)"
Also just in case you're testing this page with no parameters, I would change var params = getParams(); to var params = getParams() || [];, which will prevent a script error and will show 'undefined' in the fields.
killx needs to address the form elements; use it like this:
Code:
function killx(theForm)
{
for (var i=0, elems=theForm.elements; i < elems.length; i ++)
elems[i].name = elems[i].name.replace(/^x/, "");
}
and call it: onsubmit="killx(this)"
Also just in case you're testing this page with no parameters, I would change var params = getParams(); to var params = getParams() || [];, which will prevent a script error and will show 'undefined' in the fields.
Hi Arty Effem, thanks for your comments. I did the modificaitons you suggested but unfortunatly I´m still not receiving the info in my CRM.
I have simplified the form so it would just have the field with the variable the script should work on. Please see below:
Code:
<body>
<head><title></title>
<script language="JavaScript" type="text/javascript">
function killx(theForm)
{
for (var i=0, elems=theForm.elements; i < elems.length; i ++)
elems[i].name = elems[i].name.replace(/^x/, "");
}
</script>
<script language="JavaScript" type="text/javascript">
<!-- Begin
function getParams() {
var idx = document.URL.indexOf('?');
var tempParams = new Object();
if (idx != -1) {
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
for (var i=0; i<pairs.length; i++) {
nameVal = pairs[i].split('=');
tempParams[nameVal[0]] = nameVal[1];
}
return tempParams;
}
}
var params = getParams();
// End -->
</script>
</head>
<body>
<form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=ISO-8859-1" name=SalesForce method="POST" onsubmit="killx(this)">
<input type=hidden name="oid" value="00D300000005zTX">
<input type=hidden name="retURL" value="http://www.liveperson.com.br/confirma_demo.htm">
<table cellpadding=0 cellspacing=4 border=0>
<tr><td>
Protocolo de contato:</td><td bgcolor=red> </td><td><input disabled id="00N30000002PCO8" maxlength="51" name="x00N30000002PCO8" size="20" type="text" />
</td></tr>
<tr><td colspan=3>
<br><input type="submit" name="submit" value="Requisitar Demo">
</td></tr>
</table>
</form>
<script language="JavaScript" type="text/javascript">
<!-- Begin
pvName = unescape(params["protocolo"]);
if (pvName) document.SalesForce.x00N30000002PCO8.value = pvName;
// End -->
</script>
</body>
</html>
I just thought of something are you required to have the 'name' and 'id' be the same value or could you edit one and have your CRM recognize it by the other?
Or is it possible that you can write a function to change the name and id in some way but save the original to an array to be changed back right before submit?