Link to home
Start Free TrialLog in
Avatar of dkbailey1
dkbailey1

asked on

How do I create a Coldfusion text custom format of XXXXXXXX-XXXX

I need to create a Coldfusion text custom format of XXXXXXXX-XXXX.  Is Javascript the only way?  Can someone post a similar example?

Thanks.
Avatar of bwasyliuk
bwasyliuk

I assume you are talking about form input?

Have you tried the Mask attribute of CFInput?

<cfinput type="text" name="example" mask="XXXXXXXX-XXXX" />

According to the documentation, the X means you want to allow A-Z, a-z, and 0-9
bwasyliuk,

Didn't see your post until I submitted mine. Exactly what I was going to suggest, but you beat me to it.

M@
Avatar of dkbailey1

ASKER

bwasyliuk,

Got the following error message when I tried the masking:

Context validation error for tag CFINPUT.  
The tag must be nested inside a CFFORM tag.  
 
Any ideas?

Thanks.
Changed my form to cfform but the masking isn't working.
Can you view source on the page and "cut-and-paste" into here the code for the field that you have the mask set on?
<INPUT TYPE="text" NAME="logbookWON">

It looks like the masking is not being written into the page.
So you are not getting an error now?

M@
No.  But the masking is not working.  I supposed that the mask should be written to the page, but according to the above 'paste', the mask definition is not being written out to the page.

Any ideas?
I just created a test form using the above <cfinput that I posted:

<cfform name="test" action="post">
<cfinput type="text" name="example" mask="XXXXXXXX-XXXX" />
</cfform>

This works as expected, when you type in a value, the dash "-" is inserted for you, and you cannot type past the length of the string defined in the mask.

The code the CF outputs (when I view the source) is:

<input name="example" id="example" type="text" onkeyup="mask_onValueChanged();" onfocus="mask_onSetFocus(this, 'XXXXXXXX-XXXX');" onblur="mask_onKillFocus();" />
My webpage when submit button is clicked, submits itself.  So my action ="mywebpagename", where you are using 'post'.  I wonder if that has something to do with it.
I was just typing a quick example, action="post" doesnt even make sense.

The fact that it is a cfform is what triggers the validation scripts to be added.

Both
<cfform name="test">
<cfinput type="text" name="example" mask="XXXXXXXX-XXXX" />
</cfform>

AND
<cfform name="test" action="myotherpage" method="get">
<cfinput type="text" name="example" mask="XXXXXXXX-XXXX" />
</cfform>

will work.
Can you share your updated form code?
Here is my CFFORM code:

 <cfform name = "newLogbook" action = "addLogbook.cfm" method = "post">
  <table border="0" cellspacing="0" cellpadding="2">
 
   <tr>
      <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Logbook SN:</font><br>
            <input name = "logbookSN" type = "text" class="formFields" size = "15">
      </td>
   </tr>
   
   <tr>
      <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">TMS:</font><br>
            <select class = "formFields" name = "TMS">
                       <option value = ""></option>
                        <cfoutput query = "qTMS" group="TMSCatagory">
                              <optgroup label="#qTMS.TMSCatagory#" class="#qTMS.TMSCatagory#">
                                    <cfoutput>
                                             <option value = "#qTMS.TMSID#">#TMS#</option>
                                    </cfoutput>
                              </optgroup>
                        </cfoutput>
               </select>
      </td>
   </tr>
   
   <tr>
      <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">JON:</font><br>
            <input name = "logbookJON" type = "text" class="formFields" size = "10">
      </td>
   </tr>
   <tr>
      <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">WON:</font><br>
<!---      <input name = "logbookWON" type = "text" class="formFields" size = "15" onChange="return jsValidateWON();">  --->
<cfinput type="text" name="logbookWON" mask="XXXXXXXX-XXXX"/>
      <br>
      <span class="style1">Format:  XXXXXXXX-XXXX</span>
      </td>
   </tr>
         
   <tr>
      <td><input name = "submit" type = "submit" class="formButton" value = "Add Logbook"></td>
   </tr>
   
  </table>
  <br>
  <br>
 
</cfform>
I cut and pasted this into a page on my server - and it works great.  Runs exactly as expected.

Is this the whole page, or is there something else going on?  

Which version of CF are you using?
Its not the whole page, just the CFFORM.  We are on version 6,1,0,63958.  Do we need to be using a later version?
ASKER CERTIFIED SOLUTION
Avatar of bwasyliuk
bwasyliuk

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok, thanks!  I have a crude little Javascript built.  Tried your last suggestion, but it didn't work.  Its time to move on, you get the points. Have a good day!