Clauses and JS message

Asked

Viewed 45 times

0

I need that when $DsTpVeiculo for Cavalo Truck o input be filled and show a message asking to fill in, and if it is Truck or Bitruck should not be filled out showing a message either. Some message in JS.

Code:

<?php  
   if($DsTpVeiculo == 'Cavalo Truck'){ ?>
    <td><input type="text" id="carreta" name="NrPlacaCarreta" value="<?php echo $NrPlacaCarreta; ?>"/></td>
<?php 
   }elseif($DsTpVeiculo == 'Bitruck' || $DsTpVeiculo == 'Truck'){ ?>
    <td><input type="text" id="carreta" name="NrPlacaCarreta" value="<?php echo $NrPlacaCarreta; ?>"/></td>
<?php
   }
?>

2 answers

0

When it is truck or bitruck, disable the input using the message you can use Alert(), more or less like this.

if($DsTpVeiculo == 'Bitruck' || $DsTpVeiculo == 'Truck'){ 

    echo '<script type="text/javascript">alert("Mensagem!");</script>';
?>
    <td><input disabled="true" type="text" id="carreta" name="NrPlacaCarreta" value="<?php echo $NrPlacaCarreta; ?>"/></td>

0

You can solve your problem like this:

    <?php  
        $DsTpVeiculo = "Cavalo Truck";

        if($DsTpVeiculo == 'Cavalo Truck'){ 
            $NrPlacaCarreta = "Meu preenchimento de input;";
    ?>
    <td><input type="text" id="carreta" name="NrPlacaCarreta" value="<?php echo $NrPlacaCarreta; ?>"/></td>
    <?php 
       }elseif($DsTpVeiculo == 'Bitruck' || $DsTpVeiculo == 'Truck'){ 
            $NrPlacaCarreta = "";
    ?>
        <td><input type="text" id="carreta" name="NrPlacaCarreta" value="<?php echo $NrPlacaCarreta; ?>"/></td>
    <?php
       }
    ?>
    <script>
        var DsTpVeiculo = "<?php echo $DsTpVeiculo; ?>";
        if(DsTpVeiculo == "Cavalo Truck"){
            alert("Minha mensagem Cavalo Truck");
        }else if(DsTpVeiculo == "Bitruck" || DsTpVeiculo == "Truck"){
            alert("Minha mensagem Bitruck ou Truck");
        }
    </script>

Browser other questions tagged

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