Criticizing empty field in PHP

Asked

Viewed 71 times

1

Hello. I have a code in Php that at a certain time returns me an input value:

<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 value. I need to criticize if the value value is empty, show nothing.

I’ve tried the following:

<script type="text/javascript" src="http://code.jquery.comjquery.js"></script>
<script type="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?

1 answer

1

First I’d trade an excerpt of your code for htmlentities, to avoid problems with the impression of 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 in the form Ubmit, and not in the change of a single element:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.