I have started to learn VBScript and I want to validate a HTML form / web page elements using VBScript .
Can anyone tell me if it is possible to refer an external HTML form/web page to the VBScript code and validate it's elements inside the script?
Like, I want to add a form reference or location (designed in HTML) in VBScript and validate its textbox, checkbox and submit it.
FYI, I can validate a HTML form simply by adding the VBScript part on the HTML code.
Example:
<html>
<head>
...
</head>
<body>
<script type="text/vbscript">
...
</SCRIPT>
<FORM NAME="Form1">
...
</FORM>
</body>
</html>
<HTML>
<HEAD><TITLE>Simple Validation</TITLE>
<SCRIPT LANGUAGE="VBScript">
<!--
Sub Submit_OnClick
Dim TheForm
Set TheForm = Document.ValidForm
If IsNumeric(TheForm.Text1.Value) Then
If TheForm.Text1.Value < 1 Or TheForm.Text1.Value > 10 Then
MsgBox "Please enter a number between 1 and 10."
Else
MsgBox "Thank you."
End If
Else
MsgBox "Please enter a numeric value."
End If
End Sub
-->
</SCRIPT>
</HEAD>
<BODY>
<H3>Simple Validation</H3><HR>
<FORM NAME="ValidForm">
Enter a value between 1 and 10:
<INPUT NAME="Text1" TYPE="TEXT" SIZE="2">
<INPUT NAME="Submit" TYPE="BUTTON" VALUE="Submit">
</FORM>
</BODY>
</HTML>
I want to validate a HTML form / web page elements using VBScript
This is very bad decision. Your solution will work only under Internet Explorer.
On client side strongly recomend to use JavaScript
On server sode of couse VBScript.
Related
I am currently working on an ePubv3 book and have run into a problem. I'm using Sigil as the IDE. My goal is to allow the reader to type in the page number that they would like to jump to. Here is my code:
<head>
<title>testing</title>
<script>
function goToPage() {
var pageNumber = document.getElementById('page-number').value;
</script>
</head>
<body>
<p> </p>
<form method="post" onsubmit="goToPage" action="#">
<label for="page-number">Enter page number:</label>
<input type="text" id="page-number" name="page-number"><BR>
<p class="submit">
<input type="submit" value="Go to page"></input>
</p>
</form>
</body>
</html>
I have tried a few different ways. With and without the "class" option, changing the javascript. But haven't been able to get it to work.
Would someone please tell me what I am doing wrong?
Thank you
The goal is to allow the reader to type in a number to go to that page. An example being that they want to go to page 33 (from say page 2). They would just type in 33 in the input box and go to that page.
It is simple example HTML for demonstration my issue
<!DOCTYPE html>
<html>
<body>
<div>
<label>This value comes from internal</label>
<div>
<div name='internal'>$11.11</div>
</div>
<div>
<label>This value comes from external</label>
<div>
<input type ='text' name='internal' readonly='true'>
</div>
</div>
</body>
</html>
//Display in Web Browser
This value comes from internal
11.11
This value comes from external
55.55
I want to get $55.55, but I searched "//*[text()='$55.55']" with inspector but I could not find any $55.55
and I figured out this $55.55 value comes from external JS and changed DOM and display.
This value displayed on browser but I could not get Xpath of input value
How can I get Xpath get this value "$55.55"
Thank you
Well, I dont know if I correctly understand your question, but if your goal is to get the input's value you can do something easy as, without the need of XPath:
var myInputValue = document.querySelector('input[name=internal]').value;
console.log(myInputValue);
I have code like this
<html>
<head>
<title></title>
</head>
<body>
<%
Function GetGUID()
GetGUID = CreateObject("Scriptlet.TypeLib").GUID
End Function
if Request.ServerVariables("REQUEST_METHOD") = "POST" then
if session("token") = cstr(Request.Form("csrftoken")) then
response.write("Same")
else
response.write("different")
end if
else
dim token
token = GetGUID()
session("token")=token
end if
%>
<form method="post" action="test.asp">
<input type="text" name="nama" placeholder="Input name">
<input type="submit" value="submit">
<input type="hidden" value="<%= session("token") %>" name="csrftoken">
</form>
</body>
</html>
But when I click the submit button, different always be printed. I'am very sure that those variable(session & csrftoken) have the same value, because I already check that via printing those variable.
UPDATE
Thanks all for all your help, the problem is fixed now. It's because GUID that return null-terminated string.
For reference you can see here: Link. Thanks Lankymart for the reference :)
Do not ask me WHY, but there are 2 chars at the end of your CreateObject("Scriptlet.TypeLib").GUID which are somehow lost when pushing it through as post. I will update this answer as soon as I find out more, but for now, you could just compare all the "real" chars, by making a left of the session variable by the length of the request variable. like this:
if left(session("token"), len(Request.Form("csrftoken"))) = Request.Form("csrftoken")then
Also: you can use trim instead of cstr. It implies a cstr and trims the string.
Edit:
So the "Why" part got answered in the question linked by #Lankymart. Thanks!
I`m newbie in jquery.
Got the following code:
`` `
How do I validate the textbox for user input required on clicking the button save and display error message next to the save button?
There appears to be a Validation Plug-In for jQuery. Have you looked at this already?
If not, it appears to do exactly what you want, and there is plenty of documentation right there to get started.
You can try something like
<html>
<head>
<script type="text/javascript">
function Test(txtCheck, lblCheck)
{
if (txtCheck.value == "")
lblCheck.innerHTML = "Textbox is empty";
else
lblCheck.innerHTML = "";
}
</script>
</head>
<body>
<input type="text" id="txtCheck" />
<input type="button" value="Save" onclick="Test(txtCheck, lblCheck);"/>
<label id="lblCheck"/>
</body>
I have a VBScript function in my ASP.net Page I have a small test function as shown below
<script type="text/vbscript">
sub testmePlease()
msgbox("Hello World")
end sub
</script>
I have a button in my webform and I am calling the function onclientclick as shown below
<asp:Button ID="btnAccept" runat="server" Text="Accept Settlement" OnClientClick="testmePlease()"/>
For some reason I get this end of statement expected javascipt error. What can be wrong??
I'm assuming you're using IE. Once Internet Explorer finds first <script> tag in your page, it assumes it's language as default.
Try this:
<script type="text/javascript">var foobar = false;</script>
<script type="text/vbscript">
sub testmePlease()
msgbox("Hello World")
end sub
</script>
And change your button to:
<asp:Button ID="btnAccept" runat="server"
Text="Accept Settlement"
OnClientClick="return testmePlease()"/>
Everything else should run ok.