Skip to main content
Inspiring
November 30, 2009
Answered

How to add extra character during input

  • November 30, 2009
  • 1 reply
  • 438 views

Lets say I have a form that contains a field name citycode, and the value entered could be xyz, abc, ddx, etc..any three letter combination.

What I want to do is add an extra character in front of the entered value, if the city is New York. So if the New York user enters xyz in the city code field, than tabs to to the next field, I want to automatically add 'N' in front of the entered xyz so that that the city code will display NXYZ, even though he entered xyz and is now at the next field.

How can this be done ? I konw I can check for the city during insert and then add  the N in front of xyz to insert into the table, but I thought adding it during input might be better so that the new value can be displayed before inserting into the table.

This topic has been closed for replies.
Correct answer BKBK
if the New York user enters xyz in the city code field, than tabs to to the next field, I want to automatically add 'N' in front of the entered xyz so that that the city code will display NXYZ, even though he entered xyz and is now at the next field.

<cfform>
<cfinput type="text" name="citycode" onBlur="javascript:this.value='N'+this.value.toUpperCase();">
</cfform>

1 reply

BKBK
Community Expert
BKBKCommunity ExpertCorrect answer
Community Expert
November 30, 2009
if the New York user enters xyz in the city code field, than tabs to to the next field, I want to automatically add 'N' in front of the entered xyz so that that the city code will display NXYZ, even though he entered xyz and is now at the next field.

<cfform>
<cfinput type="text" name="citycode" onBlur="javascript:this.value='N'+this.value.toUpperCase();">
</cfform>