Forums
This topic is locked
ASP variables in Javascript
Posted 22 Feb 2008 20:11:02
1
has voted
22 Feb 2008 20:11:02 wake boarder posted:
I am trying to take preselected user choices stored as asp variable/session and enter them into a form field with Javascript.The problem I run into is that the form populates with <%=....%> in the field rather than the value of the variable. If I remove the " " from the variable I get a javascript error.
Any help/ideas would be greatly appreciated.
Ex: So color one should populate with #FFFFFF (The value of the ASP variable) but instead I get <%=cPick1%>.
Here's the code I am using.
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var FeatureValue1 = "";
var FeatureValue2 = "";
var FeatureValue3 = "";
var FeatureValue4 = "";
function CopyCurrent(form) {
if (form.copy.checked) {
InitSaveVariables(form);
frmCopy.FeatureValue1.value = "<%=cPick1%>";
frmCopy.FeatureValue2.value = "<%=cPick2%>";
frmCopy.FeatureValue3.value = "<%=cPick3%>";
frmCopy.FeatureValue4.value = "<%=cPick4%>";
}
else {
frmCopy.FeatureValue1.value = FeatureValue1;
frmCopy.FeatureValue2.value = FeatureValue2;
frmCopy.FeatureValue3.value = FeatureValue3;
frmCopy.FeatureValue4.value = FeatureValue4;
}
}
// End -->
</script>
Replies
Replied 29 Feb 2008 11:27:16
29 Feb 2008 11:27:16 Georgi Kralev replied:
Hi wake,
If this syntax <b>"<%=cPick1%>"</b> considers the ASP code as string and does not execute it properly try to write it in different way.
For example replace
frmCopy.FeatureValue1.value = "<%=cPick1%>";
frmCopy.FeatureValue2.value = "<%=cPick2%>";
frmCopy.FeatureValue3.value = "<%=cPick3%>";
frmCopy.FeatureValue4.value = "<%=cPick4%>";
with:
frmCopy.FeatureValue1.value = <%= """" & cPick1 & """" %>;
frmCopy.FeatureValue1.value = <%= """" & cPick2 & """" %>;
frmCopy.FeatureValue1.value = <%= """" & cPick3 & """" %>;
frmCopy.FeatureValue1.value = <%= """" & cPick4 & """" %>;
I hope this helps.
Regards,
Georgi Kralev
Homepage: gdkralev.googlepages.com
If this syntax <b>"<%=cPick1%>"</b> considers the ASP code as string and does not execute it properly try to write it in different way.
For example replace
frmCopy.FeatureValue1.value = "<%=cPick1%>";
frmCopy.FeatureValue2.value = "<%=cPick2%>";
frmCopy.FeatureValue3.value = "<%=cPick3%>";
frmCopy.FeatureValue4.value = "<%=cPick4%>";
with:
frmCopy.FeatureValue1.value = <%= """" & cPick1 & """" %>;
frmCopy.FeatureValue1.value = <%= """" & cPick2 & """" %>;
frmCopy.FeatureValue1.value = <%= """" & cPick3 & """" %>;
frmCopy.FeatureValue1.value = <%= """" & cPick4 & """" %>;
I hope this helps.
Regards,
Georgi Kralev
Homepage: gdkralev.googlepages.com