...

View Full Version : Javascript and Active Server Page variable references



btcodeman
10-08-2003, 03:08 PM
I am having a bit of trouble getting my ASP section of code in below script to recognise and work with JS declared/assigned variable:-

The problem is in S3.2 - it says that the field is undefined. The purpose of this script is that it recieves the querystring of v_aqarr( which is an array) and v_totarr (array len) from another script). Once in my code I split into an array again to allow me to track question titles which are within the array. I then use these values to extract specific field names from source form. I know I could probably use elements direct via JS but I would like to go down this route if possible. Any ideas appreciated.

<%@ Language=JavaScript %>
<% Response.Buffer = "True" %>
<%
// S2 - Detect/Assign catch Vars
var v_aqarr = Request.QueryString("v_aqarr");
var v_totarr = Request.QueryString("v_totarr");
%>
<script language="Javascript">

// S3 - Assign Loop Controls
var v_fldarrcnt = <%=v_totarr%>;
var v_aqarr = '<%=v_aqarr%>';
var v_aqarr = v_aqarr.split(",");
document.write("Count = "+ v_fldarrcnt);
// S3.1 - Execute Loop
for (i=0; i < v_fldarrcnt ; i++) {
v_fldname = v_aqarr[i];
document.write("Debug - Field = " + v_fldname);
// S3.2 - Assign Field / Value from Questions
<%
var v_fldvalue = Request.Form(v_fld);

Response.Write("v_fldvallue = " + v_fldvalue);
%>
}
alert("Loop Complete");
</script>
%>

Roelf
10-08-2003, 09:34 PM
in this line:

var v_fldvalue = Request.Form(v_fld);

you try to enter the value from a posted (method = post) formfield into variable v_fldvalue. The fieldname you are querying is stored in the variable v_fld. As far as i can see in your code, this variable is not filled with a value, so it is undefined. i think it is trying to look at a formfield with the name: undefined, this is prbably not found

btcodeman
10-08-2003, 09:39 PM
Originally posted by Roelf
in this line:

var v_fldvalue = Request.Form(v_fld);

you try to enter the value from a posted (method = post) formfield into variable v_fldvalue. The fieldname you are querying is stored in the variable v_fld. As far as i can see in your code, this variable is not filled with a value, so it is undefined. i think it is trying to look at a formfield with the name: undefined, this is prbably not found

Sorry typo error by myself - should read as :-

var v_fldvalue = Request.Form(v_fldname);

With the above the correct variable is being referenced but the <% ASP %> section below cannot read the value - why is this ?? Ideas appreciated..

Roelf
10-09-2003, 07:18 AM
is your form POSTed or do u use method="GET" in the form tag

btw, are you trying to execute a piece of asp-code a few times by using a client side for loop? That will not work!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum