Forum Moderators: open

Message Too Old, No Replies

Passing a variable to a form

         

llmm123

2:16 pm on Mar 27, 2007 (gmt 0)

10+ Year Member



Hi all,

Dont know if this can be easily done...

I have a whole lot of HTML pages that have a "request for information" form at the bottom of each page. This form is just your basic name,surname etc etc and then a submit button which sends an email to me with all the info entered by the user. As I said, each one of my 100+ product pages has this form.

Because all my pages use the same form, I was thinking of taking out this form from each page and instead just have a link on each page to this form (as a seperate page). I would then call this form-page as a pop-up, the user can then enter his/her details and submit.

My problem is that I would need to know FROM WHICH PRODUCT PAGE the request came from. So I was thinking of using querystrings...... I know how to pass the string

<a href='formpage.html?ProductCode=1111'>Click Here</a>

My problem is how to access/read this query string in my formpage.

What I want to do with the info (querystring) is to have it as the subject of the email that is sent to me.

Hope this makes sense!?

Any help greatly appreciated.

LL

Trace

3:08 pm on Mar 27, 2007 (gmt 0)

10+ Year Member



I often use a little Javascript function to retrieve the parameters;

function getURLParam(strParamName){
var strReturn = "";
var strHref = window.location.href;
if ( strHref.indexOf("?") > -1 ){
var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
var aQueryString = strQueryString.split("&");
for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
var aParam = aQueryString[iParam].split("=");
strReturn = aParam[1];
break;
}
}
}
return strReturn;
}

Use it like this;
alert(getURLParam('WhateverYourParameter'));

llmm123

3:21 pm on Mar 27, 2007 (gmt 0)

10+ Year Member



Hi Trace,

Thanks for this... I have seen this code, but dont know how I would use this in my form. Sorry, but I'm not clued-up on javascript AT ALL!

I know this bit of code that you gave me will produce a "pop-up" (alert) which contains my variable, but how can I use that variable in, for instance, a text field / hidden text field.

Thanks for your help!

LL

Trace

8:16 pm on Mar 27, 2007 (gmt 0)

10+ Year Member



Instead of the alert, do something like this;

document.YourFormName.YourFieldName.value = getURLParam('WhateverYourParameter');

llmm123

8:29 am on Mar 28, 2007 (gmt 0)

10+ Year Member



Thank you very much Trace - I am going to give this a GO!