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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Null value from empty text box on form

Status
Not open for further replies.

nogero

Programmer
Mar 1, 2007
43
US
I have a simple html form that calls an asp page to process the data and do an insert into an SQL Server 2005 table.

The issue is that if a user leaves a field in the form blank an empty string (or blank space) gets inserted into the database field. I would like to have a Null inserted into the database if the html form field is left blank (My database table does accept NULL values).

I am not sure how to do this, any help would be appreciated. Thanks.. Can this be done on the html form side or does this need to be done in the .asp processing page?
 
Just test the request (suppose being post and similarly for the get) object. If the posted value of the field with name "fieldname" is empty, replace it by null (reserved word).
[tt]
x=request.form("fieldname")
if trim(x)="" then
x=null
end if
[/tt]
Then use the x in the insert into statement as usual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top