• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 699
  • Last Modified:

PHP or jquery line by line data validation

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?

Thanks!!
0
zack4x4
Asked:
zack4x4
1 Solution
 
Michel PlungjanIT ExpertCommented:
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 = chkbox.id.split("_")[1]; // get the id prefix
  document.getElementById(id+"_fld1").disabled=disable;
  document.getElementById(id+"_fld2").disabled=disable;
}

assuming
<input type="checkbox" id="chk_line1" onclick="chk(this)" ....> ... <input id="line1_fld1" ...>
0
 
Julian HansenCommented:
Maybe post more detail about your code.

Even though items are being created dynamically that does not stop you from validating the new items.
0
 
joomla_phpCommented:
Is there a final submit? Gray it out until the fields are valid. If not, put a message to the right of each line.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Kyle HamiltonData ScientistCommented:
Or you could make the checkbox automatically 'checked' with JavaScript if the field is not empty.
0
 
Ray PaseurCommented:
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.
http://jquery.com/
http://jqueryui.com/
http://docs.jquery.com/Tutorials
http://docs.jquery.com/Main_Page
0
 
zack4x4Author Commented:
Thanks for your help!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now