Forum Moderators: open

Message Too Old, No Replies

Written in VBScript

JavaScript combined with VBScript

         

white300z

3:49 pm on Jun 17, 2004 (gmt 0)

10+ Year Member



I have a form that looks like the following, however what I need to do is be able to replace the number 30 (in the input type=text tag) with other numbers via a variable(strNumber). What the JavaScript function does is make sure that the number entered in the box is divisible by 30. I need to set it up so that the number entered in the box is divisible by whatever number is pulled out of the database.
<%
strNumber = 25
%>

<script type="text/javascript">
<!--
String.prototype.isFactor = function (n) {return this / n == Math.round(this / n)}
// -->
</script>
</head>

<body>
<form method="post" action="delete2.asp">
<input type="text" name="Quantity" size="2" onchange="if (!this.value.isFactor(30)) {alert('Please enter a Quantity Ordered amount divisible by 30'); this.value=''; this.focus()}">
<input type="submit">
</form>
</body>

DrDoc

4:48 pm on Jun 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The reason it's not working is because you are trying to combine the two. The VBScript is running on the server. The JavaScript is running on the client side. You need to change the JavaScript syntax to work independently.

white300z

5:04 pm on Jun 17, 2004 (gmt 0)

10+ Year Member



I've been trying to write that line in a response.write statement, however I'm getting errors:

Response.write ("<input type=text name=Quantity size=2 tabindex=25 onchange="if (!this.value.isFactor(30)) {alert('Please enter a Quantity Ordered amount divisible by 30'); this.value=''; this.focus()}">")

Can't double quotes simply be replaced with &#34;?

Thanks,

Jim

john_k

5:07 pm on Jun 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this:

Response.Write "<input type=""text"" name=""Quantity"" size=""2"" onchange=""if (!this.value.isFactor(" & strNumber & ")) {alert('Please enter a Quantity Ordered amount divisible by " & strNumber & "'); this.value=''; this.focus()}"">" & vbCrLf

(You just need to double up the quotation marks)

john_k

5:12 pm on Jun 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



btw - the another way to do this is:

<input type="text" name="Quantity" size="2" onchange="if (!this.value.isFactor(<%= strNumber %>)) {alert('Please enter a Quantity Ordered amount divisible by <%= strNumber %>'); this.value=''; this.focus()}">

[edited by: DrDoc at 5:15 pm (utc) on June 17, 2004]
[edit reason] Removed smilies from code [/edit]

white300z

5:19 pm on Jun 17, 2004 (gmt 0)

10+ Year Member



EXCELLENT

Thanks john_k,

I tried your first suggestion by doubling up on the quotes. I know I have seen that before but was thinking &#34; for some reason.

Thank you very much for your help,

Jim