<html>
<body>
<script type="text/vbscript">
Function sub()
Ms=MsgBox(UN, 1)
End Function
</script>
Username: <input
id="UN"
type=text>
<br/>
Password: <input
name="PW"
type=password>
<br/>
<input
name="Submit"
type=submit
onclick="sub()">
</body>
</html>
When the submit button is pressed, the function doesn't show the MsgBox at all. Let alone the username..
You are using a reserved word, just change Function sub() to something like Function mySub() and it will work.
If you want the value, then you need to do Ms=MsgBox(UN.value, 1) instead of Ms=MsgBox(UN, 1)
Related
I have this code that needs to be adapted to work with something similar to the code below the commented line. If I can make it without many changes would be perfect so that I don't need to change the CSS and so. Any help? Many thanks in advance.
<!-- The code to be adapted is this: -->
<form action="" id="search-form">
<fieldset>
<input type="text" class="text" /><input type="submit" value="Search" class="submit" />
</fieldset>
</form>
<!-- The new code that I got from the web and that needs to be adapted to the old one
is the following: -->
<textarea id="Blah"></textarea><button onclick="search()">Search</button>
<script>
function search() {
var Blah = document.getElementById("Blah").value;
location.replace("https://www.google.com/search?q=" + Blah + "");
}
</script>
I'm imagining you probably want something like
document.querySelector("#searchButton").addEventListener("click", ()=>{
const value = document.querySelector("#searchBox").value;
const url = `https://www.google.com/search?q=${encodeURIComponent(value)}`;
window.location.replace(url);
});
<fieldset>
<input type="text" class="search" id="searchBox">
<Button id="searchButton">Search</button>
</fieldset>
The id attribute on HTML elements allows you to access them via JavaScript. There's a wealth of tutorials online if you want to learn JavaScript deeply, but the basics of what this is doing is:
It finds the HTML element with the id of searchButton, and adds a click listener to it --- this gets triggered whenever that element is clicked.
In that listener, we find the value of the text input with the id of searchBox.
We compose our new URL. One thing I've added here is a call to encodeURIComponent to correctly handle the cases where they try searching for something which contains a character which isn't valid in a URL --- for example, the space character etc.
It was not working as I wanted, but a little trick made it work.
Here is my final code:
<form action="" id="search-form">
<fieldset>
<input type="text" class="search" id="searchBox">
<input type="submit" value="Search" class="submit" />
</fieldset>
</form>
<script>
let myvar;
document.querySelector(".submit").addEventListener("click", ()=>{
const value = document.querySelector("#searchBox").value;
myvar = `https://www.google.com/search?q=${encodeURIComponent(value)}`;
setTimeout(callurl, 1);
return false;
});
function callurl() {
location.assign(myvar);
return false;
}
</script>
I'm using Parcel. I'm trying to call a function from a form oninput event in HTML.
I keep getting an error that the function is undefined, even though I have the script tag before the form.
I simply run parcel index.html to start the webserver with the following code:
export function formInputChanged(input: HTMLInputElement, output: HTMLOutputElement){
output.value = input.value;
}
<html>
<header>
</header>
<body>
<script src="./formChanges.ts"></script>
<form id="input_form">
<input type="range" name="min_lvr" value="20" min="0.0" max="100" step="1"
oninput="formInputChanged(this, txt_min_lvr);">
<output name="txt_min_lvr" for="min_lvr" value="min_lvr.value"></output>%
</form>
</body>
</html>
I know I can do the update inline in the HTML code, but I would like to know how to do it with an external function.
try binding your function(event handler) to the DOM element directly
<html>
<header>
</header>
<body>
<script src="./formChanges.ts"></script>
<form id="input_form">
<input id="range_input" type="range" name="min_lvr" value="20" min="0.0" max="100" step="1"
oninput="formInputChanged(this, txt_min_lvr);">
<output name="txt_min_lvr" for="min_lvr" value="min_lvr.value"></output>%
</form>
</body>
</html>
export function formInputChanged(input: HTMLInputElement, output: HTMLOutputElement){
output.value = input.value;
}
document.querySelector('#range_input').addEventListener('oninput',formInputChanged)
<html>
<head>
<script>
function myFunction() {
location.replace("https://www.w3schools.com")
}
</script>
</head>
<body>
<form action="/action_page.php">
<input type="text" name="username" pattern="[a-zA_Z].{7,}" title="Unsuccessful Login, Username must contain at least one integer and one letter, and at least 7 or more characters">
<input type="button" name="B1" value="Submit" onclick="myFunction()">
</form>
</body>
Hi, for some reason when I click the submit button, the error does not appear and it just goes directly to the page. How do I make the program check the validation and when it is ok, redirect to a new page??
I would suggest you to go by this approach
create a test.php file with the following code :
<form method="post">
Username: <input type="username" name="username" pattern="(?=.*\d)(?=.*[a-z]).{7,}" title="Must contain at least one integer and one letter, and at least 7 or more characters">
<button type="submit" value="submit" class="btn btn-primary">Submit</button>
</form>
<?php
if (isset($_POST['submit'])) { ?>
<script language="javascript" type="text/javascript">
window.location = 'your location';
</script>
<?php
}
?>
This will give you the desired functionality.
NOTE: for this to run, you will need to install xampp or wamp if you are running windows and lamp if you are running linux.
So here's the answer according to your updated code :
<html>
<head>
<script>
function myFunction() {
window.location.href = 'https://www.w3schools.com';
return false;
}
</script>
</head>
<body>
<form onsubmit="return myFunction()">
<input type="text" name="username" pattern="^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+){5,}" title="Login Unsuccessful. Username must contain at least one integer and one character, and should be atleast 5 or more characters long" required>
<input type="submit" >
</form>
</body>
</html>
The return false; statement in myFunction is very important here. It will return a false to the obsubmit event which will prevent the form from being submitted. If you remove return false; statement then also window.location will work but it will appear as if it's not working as the form will get submitted and you will see the same page rather than a redirection to another page.
I have added the onsubmit event which will call the function only when all the inputs are valid
I have created a simple form that sends data to an Excel file with an array.
Everything works great except check boxes. What I would like is if the checkbox is "checked" it will post its value into the Excel document. Currently the value assigned for the box (checked) is always pasted no matter if it is checked or not. I am unsure what code is needed for the arr(6).
<script>
function PrintFunction() {
window.print();
}
</script>
<script type="text/vbscript">
function test()
dim oApp, oWB, arr
set oApp = CreateObject("Excel.Application")
oApp.visible=false
set wb = oApp.Workbooks.Open("C:\(PATH TO DB)\DB.xls",,,,"password")
redim arr(6)
arr(0) = Date()
arr(1) = Form1.text1.Value
arr(2) = Time()
arr(3) = Form1.text2.Value
arr(4) = Form1.text3.Value
arr(5) = Form1.text4.Value
arr(6) = Form1.text5.Value <---Need help with this value
with wb.sheets("Data").cells(1,1).currentregion
.offset(.rows.count,0).resize(1).value = arr
end with
wb.close true
x=msgbox("Submitted." ,64, "Thank you.")
window.close()
end function
</script>
</head>
<body oncontextmenu="return false;">
<form name="Form1">
<table border="0" style="width:700px;">
<td>Date:<input value="mm/dd/yyyy" name="text1" type="text" class="inputbox" size="20" />
<tr>
<td>Time:<input value="00:00 AM/PM" name="text2" type="text" class="inputbox" size="20" /></td>
<tr>
<td>Name:<input name="text3" type="text" class="inputbox" size="23"/></td>
<tr>
<td>Location:<input name="text4" type="text" class="inputbox" size="18" /></td>
<tr>
<td><input type="checkbox" name="text5" value="checked">Checkbox Title</td>
<input type="button" value="Print" class="classname" onclick="PrintFunction()" />
<input type="button" value="Submit" class="classname" onclick="test()" />
</table>
<br>
</form>
To name a checkbox "test5" is an atrocity. Just see what it did to Josh.
This
<html>
<head>
<hta:application id = "cbxproblem">
<script type="text/vbscript">
function test()
MsgBox Form1.cbx.checked ' <---Need help with this value
MsgBox Form1.cbx.value
end function
</script>
</head>
<body>
<form name="Form1">
<input type="checkbox" name="cbx" value="pipapo" checked="checked">Checkbox Title
<hr />
<input type="button" value="Submit" onclick="test()" />
</form>
</body>
</html>
is all the code needed to present/discuss your problem. Dragging Excel and the text elements into the question is obfuscation and wasting other people's time.
Reading about the checkbox element and comparing
<input type="checkbox" name="text5" value="checked">
vs.
<input type="checkbox" name="cbx" value="pipapo" checked="checked">
should make you realize the differences between the value and the checked attribute.
Running the demo code will prove that the checked attribute is set to True or False depending on the user (not) marking/checking the box.
See this to understand why
If Form1.text5.Checked = True Then ' <-- nonono
should be
If Form1.text5.Checked Then
The value of a text box is "Checked" or "Unchecked". If I understand your problem correctly, it sounds like there is another text box on the form whose value you want to copy (though I don't see it in your HTML code; maybe you need to add it?). Something like:
If Form1.text5.Checked = True Then
arr(6) = Form1.text6.Value 'Or .Text
End If
I am submitting form via javascript by using 'document.FormName.submit()' . But this is giving me error of 'submit is not a function'. I m using IE8
<script typr="text/javascript">
function submitForm()
{
document.theForm.submit()
}
</script>
<body>
<form name="theForm" method="post">
<input type="text" name= "name">
<input type="button" name="submit" value="submit" onclick="submitForm()">
</form>
</body>
Please help me ?
problem is with your button name
i have use this its work fine
<script type='text/javascript'>
function submitForm()
{
document.theForm.submit();
}
</script>
<form name="theForm" method="post" action="default.php">
<input type="text" name="t" id="t"/><br/>
<input type="button" name="t1" value="submit" onClick="submitForm();">
</form>
use
document.forms[index].submit()
instead
Try this:
document.getElementsByName("theForm")[0].submit();
And you need to put the script after you declared the elements so :
<form name="theForm" onSubmit= "submitForm()">
<input type="text" name= "name">
<input type="submit" name="submit" value="submit">
</form>
<script type="text/javascript">
function submitForm()
{
document.getElementsByName("theForm")[0].submit();
}
</script>
Or you can use events like document onload if you want to kepp your scripts in the page head.
If your form name is FormName
try this
Action
by the way your code is missing a semicolon at the end of the statement
and a spelling mistake here
<script typr="text/javascript">
typr
Here is the problem
change it typr is nothing should be type
<script typr="text/javascript">
to
<script language="javascript">
OR
<script type="text/javascript">
I just copy your code and executed in IE8 and it worked fine, so how is not working on your IE8. May be it is because of your hierarchy. So you please give id to form and try document.getElementById to access your form and then submit method. Do some thing like this"
<script type='text/javascript'>
function submitForm()
{
document.getElementById('your_form').submit();
}
</script>
<form name="theForm" id="your_form" method="post" action="default.php">
<input type="text" name="t" id="t"/>
<input type="button" name="t1" value="submit" onClick="submitForm();">
</form>
document.getElementById("theForm").submit();
It works perfect in my case.
you can use it in function also like,
function submitForm()
{
document.getElementById("theForm").submit();
}
Set "theForm" as your form ID. It's done.