jaysch
asked on
How to pass querystring parameters to a hidden form field using Javascript
Dear Experts,
I have successfully passed querystring parameters from a link on a page:
to another form page and displayed the parameter value on the page as displayed text.
I'm using this code on my form page to retrieve the querystring values:
This is the inline code I'm using to display the querystring params as live text:
I also need to pass the same values to a hidden form fields to be included in the generated email. I've tried several methods to pass the param value to the hidden field but nothing seems to work:
I'm not sure if I should use the 'gsParam' value or try to use the Querystring method. I have set form action to method="get" but that doesn't help.
Any ideas would be greatly appreciated. I need any suggestions to be written in javascript.
Thank you!
I have successfully passed querystring parameters from a link on a page:
<a href="HomeQuote.html?code=Travelers&desc=Home">
to another form page and displayed the parameter value on the page as displayed text.
I'm using this code on my form page to retrieve the querystring values:
<script type="text/javascript">
var qsParm = new Array();
function qs() {
var query = window.location.search.substring(1);
var parms = query.split('&');
for (var i=0; i<parms.length; i++) {
var pos = parms[i].indexOf('=');
if (pos > 0) {
var key = parms[i].substring(0,pos);
var val = parms[i].substring(pos+1);
qsParm[key] = val;
}
}
}
</script>
<script type="text/javascript">
qsParm['code'] = null;
qsParm['desc'] = null;
qs();
</script>
This is the inline code I'm using to display the querystring params as live text:
<h2> <script type="text/javascript">
if (qsParm['code'] && qsParm['desc'])
document.write(qsParm['code'] + ' ' + qsParm['desc']);
</script> Insurance Quotation Request - Receive a $25 Mastercard!</h2>
I also need to pass the same values to a hidden form fields to be included in the generated email. I've tried several methods to pass the param value to the hidden field but nothing seems to work:
<script language="JavaScript">
document.write('<input type="hidden" name="Company" value="' + getQuerystring('code') + '">');
document.write('<input type="hidden" name="Type" value="' + getQuerystring('desc') + '">');
</script>
I'm not sure if I should use the 'gsParam' value or try to use the Querystring method. I have set form action to method="get" but that doesn't help.
Any ideas would be greatly appreciated. I need any suggestions to be written in javascript.
Thank you!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You're welcome, glad to help.
ASKER
Your code did the trick, works perfect!
Thanks so much for your help.