PDA

View Full Version : hunt the variable


Spudhead
12-16-2002, 04:04 PM
I have a form, and some JS validation that goes on. The validation is called by an onSubmit="return doValidation()" in the form tag - if the form fields are filled in ok, it returns true and the form submits. If not, the user's HD is immediately crushed. Or something.
The very last thing this validation JS does before returning true is alert() the value of a particular input box: "grand_total". Although the value is "" on page load, by the time the form submits it will ALWAYS have a value, and it always alerts it ok.

The page that handles this form submission looks like this:

<%
var grandTotal=String(Request.Form("grand_total").value);
Response.Write(grandTotal+"<br>");
Response.End;
%>


Which will, I promise, be added to - once I figure out why, in the name of Santa and all his Little Helpers, it currently writes "undefined<br>".

It HAS a value - at least, one that the JS validation on the previous page can read. The form field name is right, the same setup can access other fields on the form, so where has the form value gone?



ps - and no, I don't think I can get to it through the form collection or whatever it is, as a variable number of form fields are generated and I wouldn't know what index number to use.

Spudhead
12-16-2002, 05:45 PM
Getting weirder...

form handling page:

<%
var strEverything=String(Request.Form);
var grandTotal=Request.Form("grand_total").value;
var countQuotes=Request.Form("count_quotes").value;
var countChanges=Request.Form("count_changes").value;
var countPurchases=Request.Form("count_purchases").value;
var whichJob=Request.Form("job").value;
var strSuffix=Request.Form("suffix").value;
Response.Write(strEverything+"<br>"+grandTotal+"<br>"+countQuotes+"<br>"+countChanges+"<br>"+countPurchases);
Response.End;
%>


written to the page:

suffix=&quote1=qwer&quote1_cost=1&quote2=asdf&quote2_cost=200&chg1=Add+decimal+hours+capability&chg1_cost=125&pur1=A+test+purchase&pur1_cost=100&pur2=Another+test&pur2_cost=120&grand_total=546&JID=2473&job=2473&company=FOS&contact=9&count_quotes=2&count_changes=1&count_purchases=2<br>undefined<br>undefined<br>undefined<br>undefined


I can access nothing via its name, but can clearly see the whole lot in the Form collection. What's going on?



edit - just a thought but the quote marks in the querystring above are caused by my form names - "quote1", for example. When this gets put in a querystring with a "&" in front of it, a HTML parser is going to read it and put a quote:) That wouldn't cause any of this, would it? It's the ASP that's screwing up, not the HTML...

Roelf
12-16-2002, 07:05 PM
what method is used to submit the form content, if it is "get", you should use Request.Querystring, if it is "post" you should be able to get the contents with Request.Form :confused:

whammy
12-16-2002, 11:38 PM
Yeah... looks like you're using "get" and then using Request.Form (which only works with method="post").

glenngv
12-17-2002, 02:31 AM
I think the method used is POST because he can get the values of the Request.Form collection as he posted the output of the response.writes.

var strEverything=String(Request.Form);

I think the error is in the .value, are you sure there should be like that in JScript server-side? I'm not sure though coz I haven't used it :D

var grandTotal=Request.Form("grand_total").value

Spudhead
12-17-2002, 04:42 PM
Darn - you're right. It was .value

I guess I just put it in without thinking, I use usually it getting stuff out of databases. Funny though, I'm sure I've used it before in forms and had no problems.

Cheers guys.