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!!
LVL 4
zack4x4Asked:
Who is Participating?
 
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.