Criticize empty field in PHP

1

Hello. I have a code in Php that at some point returns a value of an input:

<input type="text" style="color:chocolate" size="1" id="note1" name="note1" class="mynote" value="<?php print preg_replace("/\"/", "&quot;", $message['note']); ?>" />

I work with the resulting value of the value. I need to criticize if the value of the value is empty, do not show anything.

I've already tried the following:

<script type="text/javascript" src="http://code.jquery.comjquery.js"></script><scripttype="text/javascript">
   $(document).ready(function(){
      $('#note1').hide();
      $("input").change(function(){
         $( "input option:input").each(function(){
            if($(this).attr("value")!=""){
               $("#note1").hide();
            }
            else {
               $("#note1").show();
           }
        });
      }).change();
   });
</script>

Any option in this Jquery?

    
asked by anonymous 02.10.2015 / 18:36

1 answer

1

First I would swap a portion of your code to htmlentities , so there will be no problems with printing value :

<input type="text" style="color:chocolate" size="1" id="note1" name="note1" class="mynote" value="<?php echo htmlentities($message['note']); ?>" />

And I would put the action on the submit form, not on change of an element:

$('#note1').hide();
  $('#seu_formulario').submit(function(e){
      e.preventDefault();
     $( "input option:input").each(function(){
        if($(this).val()){
           $("#note1").hide();
        }
        else {
           $("#note1").show();
       }
    });
  }).change();
    
02.10.2015 / 18:50