javascript - How can I make a js function recognize a clicked or empty checkbox? -


i'm modifiying existing form.

you can launch task block several fields, , if these empty, can remove block again. of them required, submit data complete. if not complete, can save work in process (sic! i'd have preferred work in progress...)

for code recognize empty fields, seems of them have value="". when completed, system seems to recognize not empty.

but checkbox want use causes problems.

if don't set value="", it's not recognized empty, , can't remove block.

if set value="" , it's not recognizing entered checkmark, , can't submit data complete.

i thought onclick="...." , defining way set value="true" way forward, haven't found example while searching, , being quite beginner, haven't learned yet.

the checkbox (to renumbered id 050):

<label for="completed_001">task completed<em class="labelrequired">*</em></label> <input type="checkbox" id="completed_001" name="completed_001" alt="task completed 001" title="task completed 001" value="" class="validate['required']"> 

the function: (where last row concerns checkbox)

function isemptyaction(nr) {      var pad = "000";     var nr = (pad+nr).slice(-pad.length);      return  document.getelementbyid('taskdescription' + nr).value == '' &&             document.getelementbyid('taskowner' + nr).value == '' &&             document.getelementbyid('taskduedate' + nr + '_date').value == '' &&             document.getelementbyid('documentid' + nr).value == '' &&             document.getelementbyid('resultsandcomments' + nr).value == '' &&             document.getelementbyid('completed_' + nr).value == '';   } 

= = = = = update = = = =

1) edit improvement, fellow user dmorrow!

2) tips , suggestions, got work eventually!

i removed value="" checkbox code in html. allows entered checkmark recognized, when required sumbmitting data complete.

i used document.getelementbyid('completed_' + nr).checked == false; in function checking fields empty. allows removing task block when empty.

thanks again! made me happy beginner!

on line

 document.getelementbyid('completed_' + nr).value == ''; 

if don't have value or empty value, return true. because instead of checked status, checking it's value attribute. instead need use

  document.getelementbyid('completed_' + nr).checked; 

then return true/false depending on status of checkbox.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -