Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why don't this validation works 1

Status
Not open for further replies.

cumap

IS-IT--Management
Jul 9, 2007
268
US
Hi all,

I'm pulling my hair trying to understand why this js validation is not called when submitted.
Code:
<script language="javascript">
<!--
function getValidate(theForm) {
	if (theForm.no_of_label.selectedIndex==0) 
	{
		alert( "Choose Number of Label per month!" );
		return false;
	}
	if (theForm.length_per_role.selectedIndex==0) 
	{
		alert( "Choose Length per Role!" );
		return false;
	}
	if (theForm.cost_per_role.value=="") 
	{
		alert("Empty Value of Cost/Role!");
		theForm.cost_per_role.focus();
		return false;
	} 
	
	return true;
}

-->
</script>
</head>

<body>
<table width="40%" bgcolor="#CCFF99" align="center" cellpadding="2" style="padding:5px">
    <tr>
	<form name="getsave" id="getsave" method="post" onsubmit="return getValidate(this);">
		<td align="right" nowrap="nowrap"># of label: </td>
        <td align="left"><select name="no_of_label">
            <option value=""><- Select -></option>
            <option value="300">300</option>
            <option value="400">400</option>
            <option value="500">500</option>
            <option value="600">600</option>
            <option value="700">700</option>
            <option value="800">800</option>
            <option value="900">900</option>
            <option value="1000">1000</option>
            <option value="2000">2000</option>
            <option value="300">3000</option>
        </select></td>
    </tr><tr>    
    	<td align="right" nowrap="nowrap">$/role: </td>
        <td align="left"><input type="text" name="cost_per_role" maxlength="7" size="7" /></td>
    </tr><tr>
    	<td align="right" nowrap="nowrap">Role length: </td>
        <td align="left"><select name="length_per_role">
            <option value=""><- Select -></option>
            <option value="50">50</option>
            <option value="100">100</option>
            <option value="150">150</option>
        </select></td>
    </tr><tr>
    	<input type="hidden" name="form00" value="getSave" />
    	<td colspan="2" align="center"><input type="reset" value="Clear" /><input type="submit" name="submit" value="Get Result" /></td>
	</form>
	</tr>
</table>
 
I forgot to add that this problem only work in html page. I'm trying to have it work in asp instead.
 
Hi

Then post the HTML output of that buggy ASP. Or give us an URL to a publicly accessible copy. We can not do anything else with the correct code you posted.

Feherke.
 
In case you need, here is the whole asp code
Code:
<%
if request("form00") = "getSave" then
	dim otherValue,ourSave,youSave
	dim no_of_label,cost_per_role,length_per_role
	no_of_label = request("no_of_label")
	if len(no_of_label)=0 then
		response.Redirect "error.asp?msg=Choose Number of Label/month!"
	else	
		if NOT isNumeric(no_of_label) then
			response.Redirect "error.asp?msg=Invalid Number of Label/month value!"
		end if
	end if	
	cost_per_role = request("cost_per_role")
	if len(no_of_label)=0 then
		response.Redirect "error.asp?msg=Choose Number of Label/month!"
	else
		if NOT isNumeric(cost_per_role) then
			response.Redirect "error.asp?msg=Invalid Cost/Role value!"
		end if
	end if	
	length_per_role = request("length_per_role")
	if len(no_of_label)=0 then
		response.Redirect "error.asp?msg=Choose Number of Label/month!"
	else
		if NOT isNumeric(length_per_role) then
			response.Redirect "error.asp?msg=Invalid Role Length value!"
		end if
	end if
	otherValue = FormatNumber(((cost_per_role / length_per_role) * no_of_label),2)
	ourSave = 0.33
	ourSave = FormatNumber((otherValue * ourSave),2)
	youSave = FormatNumber((otherValue - ourSave),2)
end if
%>

<script language="javascript">
<!--
function getValidate(theForm) {
	if (theForm.no_of_label.selectedIndex==0) 
	{
		alert( "Choose Number of Label per month!" );
		return false;
	}
	if (theForm.length_per_role.selectedIndex==0) 
	{
		alert( "Choose Length per Role!" );
		return false;
	}
	if (theForm.cost_per_role.value=="") 
	{
		alert("Empty Value of Cost/Role!");
		theForm.cost_per_role.focus();
		return false;
	} 
	
	return true;
}
-->
</script>

<body>
<table width="40%" bgcolor="#CCFF99" align="center" cellpadding="2" style="padding:5px">
<% if len(youSave)>0 then %>
    <tr>
    	<td align="right" nowrap="nowrap">Their Cost: </td><td align="left" nowrap="nowrap"><%=otherValue%></td>
    </tr><tr>
        <td align="right" nowrap="nowrap"><font color="#003366">Our Low Price: </font></td><td align="left" nowrap="nowrap"><font color="#003366"><%=ourSave%></font></td>
    </tr><tr>    
        <td align="right" nowrap="nowrap"><font color="#FF0000">Your Save: </font></td><td align="left" nowrap="nowrap"><font color="#FF0000"><%=youSave%></font></td>
    </tr>
<% end if %>
    <tr>
	<form name="getsave" id="getsave" method="post" onsubmit="return getValidate(this);">
		<td align="right" nowrap="nowrap"># of label: </td>
        <td align="left"><select name="no_of_label">
            <option value=""><- Select -></option>
            <option value="300">300</option>
            <option value="400">400</option>
            <option value="500">500</option>
            <option value="600">600</option>
            <option value="700">700</option>
            <option value="800">800</option>
            <option value="900">900</option>
            <option value="1000">1000</option>
            <option value="2000">2000</option>
            <option value="300">3000</option>
        </select></td>
    </tr><tr>    
    	<td align="right" nowrap="nowrap">$/role: </td>
        <td align="left"><input type="text" name="cost_per_role" maxlength="7" size="7" /></td>
    </tr><tr>
    	<td align="right" nowrap="nowrap">Role length: </td>
        <td align="left"><select name="length_per_role">
            <option value=""><- Select -></option>
            <option value="50">50</option>
            <option value="100">100</option>
            <option value="150">150</option>
        </select></td>
    </tr><tr>
    	<input type="hidden" name="form00" value="getSave" />
    	<td colspan="2" align="center"><input type="reset" value="Clear" /><input type="submit" name="submit" value="Get Result" /></td>
	</form>
	</tr>
</table>
</body>
</html>
 
You are right! it works now as you told me to do for the page. But could you tell me why with the same page, I can't get the js validation to work in my localhost. If you notice, you see that the asp script that I posted doesn't have the bug/unused regular expression in it. And it still doesn't work with js validate.
 
Nevermind Feherke, properly has something to do with refreshing and deleting all in ie to see it works. Thank you for your help, again! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top