Checkbox Value in VBscript/HTML - html

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

Related

one textbox one button two different pages in html

i am trying to assign a textbox value to a php variable now problem is i want one button to work for two different pages i.e if i enter in a text box 'a'and click on button it should redirect to 'a.php' page if i write in a text box 'b' it should redirect to 'b.php'.
so one textbox,one button two different pages.
Code :
<html><head>
<meta charset="UTF-8" />
<script>
function submitForm(action)
{
document.getElementById('a').action = action;
document.getElementById('a').submit();
}
function submitForm1(action)
{
document.getElementById('b').action = action;
document.getElementById('b').submit();
}
</script>
</head>
<body >
<h3><font face="verdana" size="3"><b>Enter Text:</b></h3>
<input type="text" align="right" style="font-size:15pt;height:32px;"><br><br>
<form action="b.php" name="b" id="b" method="post">
<form action="a.php" name="a" id="a" method="post">
<input type="submit" onclick="submitForm('a.php')" value="TRY" name="a">
<input type="button" onclick="submitForm1('b.php')" value="TRY" name="b">
</form>
</form>
</body>
</html>
You can change the action onsubmit based on the text inside the input.
<html>
<head>
<script type="text/javascript">
function onsubmit_handler(){
var myForm = document.getElementById('myForm');
var data = document.getElementById('data').value;
if(data == "a")
myForm.setAttribute('action', 'a.php');
else if(data == "b")
myForm.setAttribute('action', 'b.php');
else
myForm.setAttribute('action', 'error.php');
}
</script>
</head>
<body>
<h3>Enter Text:</h3>
<form id="myForm" method="post" onsubmit="onsubmit_handler()">
<input type="text" id="data" name="data" value="">
<input type="submit" value="Post">
</form>
</body>
</html>
Test code here : http://jsfiddle.net/Eg9S4/
use this codes buddy
<html><head>
<meta charset="UTF-8" />
<script>
function submitForm()
{
var link=document.getElementById('a');
var str1 = "a.php";
var n = str1.localeCompare(link);
if(n==1)
{
window.open("main.html");
}
else if(n==-1)
{
window.open("index.html");
}
}
</script>
</head>
<body >
<h3><font face="verdana" size="3"><b>Enter Text:</b></h3>
<input type="text" align="right" style="font-size:15pt;height:32px;"><br><br>
<input type="submit" onclick="submitForm()" value="TRY" name="a">
</form>
</form>
</body>
</html>
The problem looks to be that you're using getElementById but the input elements don't have an ID (they only have a name).
I'd also recommend attaching an onSubmit event to the form and removing the onClick events from the buttons.
Edit: After looking at the code in detail I saw that there were some other issues that were probably hindering the opersation. The most notable one was that you can't nest form tags. There were some other CSS and validation issues.
Here is some working code:
Test Page
function SubmitForm(el) {
// Get the form element so that we can set the action later
var form = document.getElementById('theForm');
// Set the action for the form based on which button was clicked
if (el.id == "A")
form.action = "a.php";
if (el.id == "B")
form.action = "b.php";
// You dont need to submit the form. It's alreasdy happening, so there is no need for an explicit call.
}
</script>
<h3 style="font-family: Verdana; font-weight: bold;">Enter Text:</h3>
<input type="text" style="font-size:15pt;height:32px;"><br><br>
<form method="post" onsubmit="SubmitForm();" action="fake.html" id="theForm">
<input type="submit" id="A" value="A" onclick="SubmitForm(this);">
<input type="submit" id="B" value="B" onclick="SubmitForm(this);">
</form>

Is there any way to set a max value on an html text input?

I am making a program that requires the user to input a string into an HTML text input box but it has to be four characters. Is there any way to set a max value for the input? Also can you make it so it can only be numbers? Here is what I mean:
<html>
<head>
</head>
<body>
<h1>Please enter a four digit pin number:</h1>
<input type=text id=pin_number **maxvalue=4**>
/*Maybe you can do it with buttons*/
<table><tr><td><input type="button" value="1>"</td><td><input type="button" value="2>"</td>
<td><input type="button" value="3>"</td></tr><tr><td><input type="button" value="4>"</td><td><input type="button" value="5>"</td>
<td><input type="button" value="6>"</td></tr><tr><td><input type="button" value="7>"</td><td><input type="button" value="8>"</td>
<td><input type="button" value="9>"</td></tr></table>
</body>
</html>
<input type="number" max="9999" min="0" required value="0">
Fiddle.
Another solution, using the HTML5 pattern attribute:
<input type='text' pattern='\d\d\d\d' />
Fiddle
Again, I'm supposing you want exactly four digits. And you can type anything you want in, but an error is thrown when you click submit
Use Javascript and regular expressions like this:
<html>
<head>
<script language="javascript" type="text/javascript">
function pinnotify() {
var notify = document.getElementById('notify');
var numberRegex = new RegExp("^[0-9]+$");
var text = document.getElementById("pin");
if(numberRegex.test(text.value)){
notify.innerHTML = '<a style="font-size:1em;">Looks good!</a>';
}else{
notify.innerHTML = '<a style="font-size:1em;">Please numbers only.</a>';
}
if(text.value.length > 4){
text.value = text.value.substring(0,4);
}
}
</script>
</head>
<body>
<h1>Please enter a four digit pin number:</h1>
<form method="post" action="">
<input type="text" name="pin" id="pin" size="32" onkeyup="return pinnotify();"> <span id="notify"></span><br/>
</form>
</body>
</html>
Here is my way to filter digits and check max value in a text field.
It works in any browser
JS function:
function InputReplaceForInt(input, max) {
if(max > 0 && input.value.length > max) {
input.value = input.value.substr(0,max);
}
input.value = input.value.replace(/[^\d]/g, '');
}
Html code:
<input name="telephone" type="text" onkeyup="InputReplaceForInt(this,11)"/>

Manually passing form data to classic asp page fails

Passing form values to the asp page from a standard html form works, but trying to pass them manually does not. Is this some oddity with ASP classic? To outline the situation, I have the following standard form:
<form name="login" id="login" method="post" action="login_process.asp">
<input name="userName" type="text" size="30" maxlength="100" />
<input name="password" type="password" size="30" maxlength="100" />
<input name="Submit" type="submit" class="btn" value="Login" />
</form>
On the receiving end (login_process.asp), I have this:
if Request.Form("Username") <> "" and Request.Form("Password") <> "" then
' do stuff here
Now the odd thing is that this form has been in place for years and actually works. But if I try passing values manually to login_process.asp the values never make it:
www.zzz.com/login_process.asp?username=some_user&password=some_password
I added some checks to login_process.asp to see if I could pull the vars from the submit before they were processed like so:
myUsername = request.form("Username")
myPassword = request.form("Password")
response.write "user=" & myUsername
response.write "pass=" & myPassword
and all I'm getting is
user=pass=
So obviously the data isn't getting passed. But why? What am I overlooking? Passing form data is basic stuff so what gives?
Any insights appreciated!
You are no longer using the form if you are passing them on the querystring, So Request.Form won't work. You need to use Request.QueryString instead.
More info here
We can use "Request.Form" to get form field data into other page. For this please try below code :
<form name="login" id="login" method="post" action="login_process.asp">
<input name="userName" type="text" size="30" maxlength="100" />
<input name="password" type="password" size="30" maxlength="100" />
<input name="Submit" type="submit" class="btn" value="Login" />
</form>
And we get the form data in login.process.asp page is something like this :
<% Response.Write(Request.Form("userName")) %>
It will display userName value

required field in html form works in chrome but not mobile or ie (done in wordpress)

I am building a form using html in wordpress. The fields that need to be required work in chrome (giving a please fill out this field when the submit button is pressed without information in the field) however it will not work in IE or mobile, it just allows the form to be submitted. Here is a sample of a field
Last name: *
input type="text" name="lastname" value="" maxlength="50" required="required"
I dont know whats going on here and Im pretty new so any help would be appreciated
(edit with answer)
This is what I ended up doing and it works now thanks for the responses
<html>
<head>
<script type="text/javascript">
function validateForm()
{
var x=document.forms["myForm"]["firstname"].value;
if (x==null || x=="")
{
alert("First name must be filled out");
return false;
}
}
</script>
</head>
<body>
<form name="myForm" form action="dlcplateFormTest.php" onsubmit="return validateForm()" method="POST">
<tr>
<td>Last name: *</td>
<td><input type="text" name="lastname" value="" maxlength="50" required="required" /> </td>
</tr>
<tr>
<input type="submit" value="Submit" /><input type="reset" value="Reset" />
</form>
</body>
</html>
you need to write a javascript function that checks if the fields are "" or not if they are "" then cancel request

VBS/HTML Can't get InputBox to pop up

<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)