Highlighted

trim function

Engaged ,
Jul 28, 2015

Copy link to clipboard

Copied

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.

Andy

Views

395

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

trim function

Engaged ,
Jul 28, 2015

Copy link to clipboard

Copied

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.

Andy

Views

396

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 28, 2015 0
LEGEND ,
Jul 28, 2015

Copy link to clipboard

Copied

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)#" />)

</cfquery>

HTH,

^_^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 28, 2015 0
Engaged ,
Jul 28, 2015

Copy link to clipboard

Copied

WolfShade,

    Thank you for the reply. That works good, but I need to catch the space before it goes to the Insert page because we don't want the same part number to be entered twice if it's in an open order. Do I need to use some javascript to catch these spaces? If so, how do I do that? Maybe this would be the best thing to do. If there are any spaces before or after the part number, have a javascript alert box say something about spaces are not allowed before or after a part number. Do you know Javascript at all?

Andy

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 28, 2015 0
haxtbh LATEST
Advocate ,
Jul 29, 2015

Copy link to clipboard

Copied

You can check it on the form submission and the insert into the database.

When you submit the form, run some javascript that will be trim the text in the inputs and then post the form. http://stackoverflow.com/questions/8120983/trim-spaces-from-form-input

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 29, 2015 0