Skip to main content
Known Participant
May 18, 2009
Question

Input field based on another input field - how do I do this ?

  • May 18, 2009
  • 2 replies
  • 614 views

I have a form with an input field. The requirement is that if a value is entered (>0) into this field, I need to popup/display anohter input field to be filled out, it is required. How do I do this ?

I have done something similar with radio buttons and javascript  (if button is check, input field popsup for entry) but have never done it with with another input field.

Can someone please provide some code to get me started ?

Thanks for any help.

    This topic has been closed for replies.

    2 replies

    Inspiring
    May 18, 2009

    Olivia,

    Using jQuery (or similar JS library), you could use the attached code to accomplish your task. You should be able to just rename this file with a .html extension and load it in your browser to test (I used the jQuery library delivered from Google's servers so you don't need to install anything to check it out).

    The attached code is client side. If someone enters a value into an input that is greater than 0, it'll show a new form field. You could do your validation server-side by checking if the value in the main input is greater than 0 and, if so, whether or not the added field is completed (and then return user to form with errors, etc., if not).

    You can also incorporate the validation client-side with jQuery but it's a tad more involved and I thought you might want to first just see how you get the right fields to display under the desired conditions with some JS.

    Inspiring
    May 18, 2009

    Find the code that worked for radio buttons and adapt it to this situation.