...

View Full Version : javascript within forms - duplicating values to create a query string in the retURL



this_end_up
12-10-2007, 07:55 PM
Hello,

I was trying to do the following...
I would like to grab the value that someone has typed into the "first_name" text input field and somehow attach it on the end of the "retURL" hidden field, so that the URL would look like this: http://www.name.com/ty.php?first_name=michael"

In other words, I would like to find a way to create a script that will create a "querystring" based on the form values. I then can populate/personalize the "ty.php" page.

I am using the following code for the form:
<form action="http://www.salesforce.com/servlet......" method="POST" />
<input type="hidden" name="oid" value="........." />
<input type="hidden" name="retURL" value="www.name.com/ty.php" />
<input maxlength="40" type="text" id="first_name" size="20" name="first_name" class="req" value="" />
<input type="submit" name="scs" id="submit" value="Submit">

Thanks guys.

Michael

rnd me
12-10-2007, 08:21 PM
var allFormsData=[];

for (var z=0; z< document.forms.length; z++){
var inputs = document.forms[z].elements;
var mx= inputs.length;
var qs=[];

for(var i=0; i<mx; i++){
if(inputs[i].name && inputs[i].value || inputs[i].checked )qs[qs.length]="&"+escape(inputs[i].name)+"="+ escape(inputs[i].checked || inputs[i].value);
var out=qs.join("").substr(1)
}
allFormsData[z]= out
}//next


alert( allFormsData.join("\n"))
/* at coding forums (some numbers slightly changed)

wysiwyg=0&styleid=0&signature=true&quickreply=1&fromquickreply=1&do=postreply&t=129444&p=who&#37;20cares&parseurl=1&loggedinuser=546546&sbutton=Post%20Quick%20Reply&preview=Go%20Advanced
do=process&searchthreadid=129444
s=3e191e52da&t=129444&pp=15&page=1&vote=5
f=2
f=2
*/

Philip M
12-10-2007, 08:22 PM
<input type="hidden" name="retURL" value="www.name.com/ty.php" />
<input maxlength="40" type="text" id="first_name" size="20" name="first_name" class="req" value="" onchange="addName(this)">

<script type = "text/javascript">
function addName(which) {
newUrl = retURL.value + "?first_name=" + which.value;
alert (newUrl); // delete after testing
}

</script>


But surely you have more than one Michael, Tom, Bill etc.????

this_end_up
12-10-2007, 08:40 PM
Hey Philip...

I can see the logice, but it doesn't seem to work.

Is there something I need to add into the "retURL" value to add the string on the back?

Thanks.

Philip M
12-10-2007, 09:07 PM
Hey Philip...

I can see the logice, but it doesn't seem to work.

Is there something I need to add into the "retURL" value to add the string on the back?

Thanks.

It works fine for me!

When I enter philip I get the alert

www.name.com/ty.php?first_name=philip

this_end_up
12-10-2007, 11:23 PM
Philip,

I see how it works...that is sort of what I want to do.

But just for kicks...this is what I want to do.

I would like to have a form with about 5 fields (first_name, last_name, title, phone, company), and when you hit the submit button, the forms action would write it to salesforce's database and the "<input type="hidden" name="retURL" value="" />" value would be generated by something similar to what you created...but using "document.write" or "return (newURL)"

Anyyways, let me know if you can help me out.

Michael

Philip M
12-11-2007, 09:04 AM
Not sure that I understand your problem. As I understand it you want the value of retURL to have the name added to the string.

<input type="hidden" name="retURL" value="www.name.com/ty.php" />
<input maxlength="40" type="text" id="first_name" size="20" name="first_name" class="req" value="" onchange="addName(this)">

<script type = "text/javascript">

function addName(which) {
newUrl = retURL.value + "?first_name=" + which.value;
alert ("newUrl = " + newUrl); // delete after testing
retURL.value = newUrl;
alert ("retURL = " + retURL.value); // delete after testing
}

</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum