Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6726759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:57:55+00:00 2026-05-26T09:57:55+00:00

I need to have some masks in my input fields in my form. I

  • 0

I need to have some masks in my input fields in my form.
I try to insert the jQuery.js and jQuery.MaskedInput.js as show in the code below:

<h:head>
    <h:outputScript name="jquery-1.6.4.min.js" library="javascript" />
    <h:outputScript name="jquery.maskedinput-1.3.js" library="javascript" />

    <script>
        jQuery(function($){
           $("#date").mask("99/99/9999");
           $("#phone").mask("(999) 999-9999");
           $("#tin").mask("99-9999999");
           $("#ssn").mask("999-99-9999");
       });
    </script>

    <title>TITLE</title>
</h:head>

<h:body>
     <h:form id="form">
        <h:inputText id= "date"  />
    </h:form>
</h:body>

BUt nothing so far.

UPDATE
With BalusC $("[id='form:phone']").mask("(99) 9999-9999"); it works fine! (thanks dude).
But I need apply this mask in a datatable :

<script>
    jQuery(function($){
       $("input.phones").mask("(999) 999-9999");
   });
</script>

<title>TITLE</title>

 <h:form id="form">

   <h:panelGrid columns="3">
        <h:outputLabel for="phones" value="Telefone(s) :" />                
        <h:dataTable id="phones" value="#{profile.user.userPhones}" var="item">
            <h:column>
                <h:inputText id= "phone" value="#{item.phone}" />
            </h:column>
            <h:column>
                <h:commandButton value="Remove" action="#{profile.removePhone}"/>
            </h:column>
            <h:column>
                <rich:message id="m_phone" for="phone" />
            </h:column>
        </h:dataTable>
    <h:commandButton value="Add" action="#{profile.addPhone}"/>
   </h:panelGrid>    

</h:form>

Any idea ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:57:56+00:00Added an answer on May 26, 2026 at 9:57 am

    JavaScript/jQuery runs in browser and works on the HTML DOM tree which is generated by JSF and sent to the browser, it does not intercept on the JSF component tree itself. Your $("#date") will return nothing as there exist no element with that ID in the HTML DOM tree. Open the page in your browser, rightclick and View Source. You’ll see that it’s actually been generated as <input id="form:date">, not as <input id="date">.

    You should instead use the following selectors (note that : is an illegal character in CSS and should thus be escaped):

    $("#form\\:date").mask("99/99/9999");
    $("#form\\:phone").mask("(999) 999-9999");
    $("#form\\:tin").mask("99-9999999");
    $("#form\\:ssn").mask("999-99-9999");
    

    or, without the need for explicit escape:

    $("[id='form:date']").mask("99/99/9999");
    $("[id='form:phone']").mask("(999) 999-9999");
    $("[id='form:tin']").mask("99-9999999");
    $("[id='form:ssn']").mask("999-99-9999");
    

    Or, alternatively, just give them a classname:

    <h:inputText id="date" styleClass="date" />
    <h:inputText id="phone" styleClass="phone" />
    <h:inputText id="tin" styleClass="tin" />
    <h:inputText id="ssn" styleClass="ssn" />
    

    which can then more generically be selected as follows without the need for fiddling with IDs of possibly multiple input fields of the same type in the view, such as inside a <h:dataTable>:

    $("input.date").mask("99/99/9999");
    $("input.phone").mask("(999) 999-9999");
    $("input.tin").mask("99-9999999");
    $("input.ssn").mask("999-99-9999");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a form where I need to remove some fields from the
we have some C++ code that we need to create a make file in.
I have a multi-step form in which some of the fields are collecting sensitive
I have some problems with performance in my code… I need to render many-colored
I need to have some object hanging around between two events I'm interested in:
I have some particular need to clone an element (image) and be draggable inside
I have some function where I need to pass a point datatype . somefunc(United
I have some data and need to create a json file with this structure
I have some files that need to be sorted by name, unfortunately I can't
I have some text that I always need to display (like a HUD). When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.