Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text box optional 3

Status
Not open for further replies.

cissilya

IS-IT--Management
Feb 15, 2005
42
US
How do i make it so that my text box is optional on my asp page.
 
I'm not sure what you mean?

Are you asking how to do the layout on the HTML form so that users will know that it is optional?

Or maybe you have an ASP that processes an HTML form... and the ASP was written by someone else and they have it coded such that it rejects forms that are missing a certain value?

Please explain more, the question is too vague.
 
or do you mean that your text box will be disabled and if you click on a check box it becomes usable, if thats what you want try this

function enabletext(which) {

if(which.checked){
document.getElementById("textboxname").disabled=false;
}else{
document.getElementById("textboxname").disabled=true;
}
}

set your checkbox like this

<input name="textboxname" type="checkbox" id="textboxname" value="checkbox" onClick="enabletext(this)">

and have your text box disabled
 
Maybe the question is an April Fools joke?
 
well what i have have is a html form, with a asp for that is tied into a access database. but if the user leaves the textbox in the html blank it returns the form with an error. i want the user to be able to leave the textbox blank if they have nothing to put in.
not sure if this makes more sense
 
Does it bounce off the ASP page or is there a client-side script that prevents the page from even being submitted?

If the former then search in your ASP for commands that would send the user back to the form such as Server.Redirect[\b] and Server.Transerfer There will probably be some sort of conditional statement immediately above this in the code that checks to see if the form element was submitted as a blank.

If the latter then look at your HTML for the form tag and check the function specified by its OnSubmit property. Inside the function you will find a conditional that checks to make sure the form element is not blank... it will return false if blank and prevent the form from being submitted.

If this is not enough info to help, then track down which method is being used to require a value in this form elment and post the appropriate code here.

 
post your code - it woould seem that you have a form validater that needs modification
 
HTML form

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Client Service</title>
<style type="text/css">
<!--
.style1 {font-weight: bold}
.style2 {font-weight: bold; }
body {
background-color: #0000CC;
background-image: url();
}
.style3 {
font-size: x-large;
font-family: Geneva, Arial, Helvetica, sans-serif;
font-weight: bold;
}
.style4 {font-size: xx-large}
body,td,th {
color: #FFFFFF;
}
-->
</style>
</head>
<body>



<form action="access.asp" method="post""script="javascript">

<div align="left">
<p align="center" class="style3 style4">Earn Intense Customer Loyalty </p>

<p align="center">


<br>
<br>
<span class="style1">First Name: </span>
<input type="text" size="30"

maxlength="50" name="First_Name">
<span class="style1">Last Name:
<input type="text" size="30" maxlength="50" name="Last_Name">
</span> <br>
<br>
<!--Division-->
<strong>Division:</Strong>&nbsp;&nbsp;&nbsp;<select id="Division" name="Division">
<option value="Boston">Boston</option>
<option value="California">California</options>
<option value="Florida">Florida</options>
</select>
<br>
<br>
<!--Supervisor-->
<strong>Supervisor:</strong> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<select id="Supervisor" name="Supervisor">
<option value="Brenda Laurenza">Brenda Laurenza</option>
</select>

<br>
<br>
<strong>Client Name </strong>:&nbsp;
<input type="text" name="client" size="100">
<br>
<br>
<span class="style2"><strong>Client Type:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong></span>
<select id="Client_type" name="Client_type">
<option value="owner">Owner</option>
<option value="architect">Architect</option>
<option value="sub">Subcontractor</option>
<option value="suffolk">abc</option>
<option value="other">Other</option>
</select>
<br>
<br>
<!--<span class="style2"><strong>If Other Specify: </strong></span>
<textarea name="ios" cols="50" rows="4"></textarea>-->
<br>
<br>
<span class="style2"><strong>How did you support Goal #2: </strong></span>
<textarea name="eicl" cols="100" ></textarea>
<br>
<br>
<input type="submit" value="Submit Form" name="Submit"align="middle">

</p>
</div>
</form>

</body>
</html>

ASP form

<!-- #include virtual="/includes/adovbs.inc" -->
<%
DIM objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath ("/goal2.mdb") & ";"
objConn.Open
%>


<%
DIM objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "Goal2", objConn, adOpenForwardOnly, adLockOptimistic, adCmdTable

objRS.AddNew
objRS("Division")=Request.Form("Division")
objRS("First_Name")=Request.Form("First_Name")
objRS("Last_Name")=Request.Form("Last_Name")
objRS("Supervisor")=Request.Form("Supervisor")
objRS("Client")=Request.Form("Client")
objRS("client_Type")=Request.Form("Client_Type")
objRS("eicl")=Request.Form("eicl")
objRS.update

objRS.Close
Set objRS=Nothing
objConn.Close
Set objConn=Nothing
%>

<%
Response.Write("<b>Thank you for submitting your Building Intense Customer Loyalty entry</b>")
%>

this is the two forms i am using. and i want for example the first name to be blank that they dont have to put that in, but if they try to submitt it when its blank it bounces back with error that authorisation erro.
 
This isnt the problem but you've got an extra quote in your form tag on the HTML page:
<form action="access.asp" method="post""script="javascript">

I don't see any validation in the ASP either, perhaps the particular field in the database has some criteria that prevents empty strings or NULLs?
 
Make sure the Required and Allow Zero Length properties for the field in your database table are set to No and Yes respectively.


Paul
 
i checked the database and it set to allow zero length. so i am not sure what is going on.

Ceal
 
You state you are getting a DB error only if the user leaves field(s) blank. This may be happening because if a field is blank, sometimes part of the actual html (quotes, etc) gets into the Request.Form element. This has happened to me before though I am not sure of the cause. What I would do to resolve this, is assigned each form element to a variable...Then check the length of the var, if it is equal to 0 then manually give it a null value. However first I would try this and see what the form elements contain...

Code:
<% 
For x = 1 to Request.Form.Count 
    Response.Write Request.Form.Key(x) & " = " 
    Response.Write Request.Form.Item(x) & "<br><br>" 
" 
Next 
%>
h/t/h

All hail the INTERWEB!
 
Did your remove the extra quote in the HTML form tag?

Which field is giving the error when blank?
 
thank you everyone i got it. Its working
 
What RhythmAddict112 is saying is that you should post a followup that explains how it was fixed because if someone uses the Search tool on this site because and finds this thread because they have the same problem that you did, they will like to know the answer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top