Is it possible to call a JS function, with a value from an ASP script?
I thought it was possible, so I tried the following method but I can't seem to get it to run. As you can see, I have an ASP variable "totalPages" in the JS call.
Response.Write "<form name=""pageSkip"" onsubmit=""return validatePageSkip("&totalPages&")"">"
I then have the JS function, which is:
function validatePageSkip(totalPages)
{
if (document.pageSkip.pn.value.length > totalPages)
{
alert("Please enter a page number within range!");
document.pageSkip.pn.focus();
return(false);
}
document.pageSkip.submit();
}
- Is this possible?
- If yes, what am I doing wrong?
UPDATE
It won't even work just using this, when I submit with an empty text box:
Response.Write "<form name=""pageSkip"" id=""pageSkip"" onsubmit=""return validatePageSkip()"" method=""post"" action=""?cpr="&pageRange&"#main"">"
Response.Write "<input type=""text"" name=""cpn"" id=""cpn"" spellcheck=""false"" autocomplete=""off"" size=""3"" class=""pageSkipBox"" value="""¤tPage&""">"
Response.Write "</form>"
With this simple JS function:
function validatePageSkip()
{
if (document.pageSkip.cpn.value.length < 1)
{
alert("Test!");
document.pageSkip.cpn.focus();
return(false);
}
document.pageSkip.submit();
}
I really don't know what is wrong. The form submits perfectly but it just won't call the function.
Can you spot anything?
validatePageSkipwritten? How? Maybe you don't have it in the proper place. Anyway, add morealertcommands into that function, one in the very beginning (before theif)