J.J.
J.J.

Reputation: 1118

Issue checking for ASP values in Javascript

I am having issues with this code, whenever the javascript can't find the value for the document.theform.Step<%=Session("checkno")%>.value it will not submit the form. On forms that have the value, there are no issues. Why would this code fail, as it checks whether or not the value exists?

Code for checking values upon form submission:

    var check940="<%=Session("check940")%>";
    var checkno="<%=Session("checkno")%>";
    if(document.theform.Step<%=Session("checkno")%>.value) {
    var check940current = document.theform.Step<%=Session("checkno")%>.value;
    if (check940=="yes" && check940current=="20")
    {
        alert("Test alert.");
    }
    }

Code for checking session variables and ensuring default value is assigned

<%
    If len(Session("check940")) <= 0 Then 
    Session("check940") = "no" 
    end if
    If len(Session("checkno")) <= 0 Then 
    Session("checkno") = "0" 
    end if
%>

When particular conditions are met, values are set to display alert in Javascript

                if (steparr(0,s)<>"20") and (docnum="940") then
                    Session("check940") = "yes"
                    Session("checkno") = d
                elseif (steparr(0,s)="20") and (docnum="940") then
                    Session("check940") = "no"
                    Session("checkno") = "0"
                end if

Upvotes: 0

Views: 45

Answers (1)

epascarello
epascarello

Reputation: 207511

You are saying that "step8 is undefined" so you can not read the value of undefined. So your check

if(document.theform.Step<%=Session("checkno")%>.value) {

needs to drop the value.

if(document.theform.Step<%=Session("checkno")%>) {

Now you are just checking to see if the element is there before doing the next step.

Upvotes: 1

Related Questions