PHP or jquery line by line data validation

Posted on 2012-08-30
Last Modified: 2012-08-31
Hi All,

   I have php script where users can enter information and dynamically add and delete lines, however the way it's coded if they don't select an option in the first radio box, the line isn't saved.  

   I was wondering what would be the best way to alert the user if they didn't select an option?  I was thinking javascript but since things can be dynamically added, I was just looking for some expert help.

   Or how could I make the other input objects readonly or disabled unless an option is picked?

Question by:zack4x4
    LVL 75

    Accepted Solution

    I do not read how you create the items and since you do not provide code, I cannot but guess the structure

    I would give each item on each line a unique Id that contained partof the checkbox id

    function chk(chkbox) {
      var disable = !chkbox.checked
      var id ="_")[1]; // get the id prefix

    <input type="checkbox" id="chk_line1" onclick="chk(this)" ....> ... <input id="line1_fld1" ...>
    LVL 50

    Expert Comment

    by:Julian Hansen
    Maybe post more detail about your code.

    Even though items are being created dynamically that does not stop you from validating the new items.
    LVL 13

    Expert Comment

    Is there a final submit? Gray it out until the fields are valid. If not, put a message to the right of each line.
    LVL 25

    Expert Comment

    by:Kyle Hamilton
    Or you could make the checkbox automatically 'checked' with JavaScript if the field is not empty.
    LVL 107

    Expert Comment

    by:Ray Paseur
    You need to know a little JavaScript (it's here to stay) to use this library, but it's the way developers are doing things like this.
    LVL 4

    Author Closing Comment

    Thanks for your help!

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    PHP Radio Array 4 27
    GPS save in database 19 20
    Hover Gone 16 16
    jquery adding parameter to hyperlink url 8 21
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
    In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now