Hi. I would like to use the Trim Function in a text box on my Add page when I insert something into our database. I just want to make sure that when users type a part number into this text box, they don't accidentally type in a space before or after the part number. Here's what my text box looks like:
<input type="text" name="Part_Number" id="Part_Number" maxlength="25" size="27" disabled="disabled">
I know how to use the Trim Function on an edit page, but not on an add page. Here's how I use it on an Edit page:
<input type="text" name="Part_Number" value="#Trim(Part_Number)#" maxlength="25" size="27">
This works because I have a value in the Part_Number field already, but how do I use this when I don't have a value entered into the database yet? Thanks for your help.
You put the trim() as the insert value in your query, not in the form input.
<cfquery name="anon" datasource="#application.dsn#">
INSERT into tableA (col1, col2, part_number)
VALUES (<cfqueryparam value="#trim(form.input1)#" />,<cfqueryparam value="#trim(form.input2)#" />,<cfqueryparam value="#trim(form.Part_Number)#" />)
You can check it on the form submission and the insert into the database.
You can then also trim it when you add it to the database. When you do the insert using coldfusion, just use the trim function then as well.