php - Display an alert message with jQuery when no option is selected from a dynamically generated drop-down list -


i want display alert message when no option selected dropdown list generated php.

i have script displays alert message when text box left blank static , easy although having trouble doing same drop down list, dropdown list selection of cars seller can offer interested buyer , changes dynamically.

any appreciated

html/php

<form method="post" id="carform" action="<?= $this->url(array('cid' => $this->cid), 'approach-to-car') ?>"> <?= csrf::tokenfield() ?> <div class="row-fluid">     <div class="span2">         job:     </div>     <div class="span10">         <select name="car" class="input-block-level">             <?php foreach ($this->cars $car): ?>                 <?php $car = car::getone($car['id']); ?>                 <?/*@var $car car */?>                 <option value="<?= $car->id ?>"><?= $car->get_title() ?></option>             <?php endforeach; ?>         </select>     </div> </div> <div class="row-fluid">     <div class="span2">         message:     </div>     <div class="span10">         <textarea name="message" rows="5" id="messageinput" class="input-block-level"></textarea>     </div> </div> <div class="row-fluid">     <div class="offset2">         <input type="submit" class="btn btn-primary" id="submitbutton" value="approach" />     </div> </div> 

jquery

<script type="text/javascript"> $("#carform").bind('submit', function(e) {     var messagevalue = $("#messageinput").val();     if (messagevalue === "") {         $("#alertbox").html("include message offer");         $("#alertbox").removeclass('hide');         e.preventdefault();         return false;     }     return true;  }); 

this jquery script isn't working me

<script type="text/javascript"> $("#carform").bind('submit', function(e) {     var carvalue = $("#input-block-level").val();     if (carvalue === "") {         $("#alertbox").html("please add car before offering buyers");         $("#alertbox").removeclass('hide');         e.preventdefault();         return false;     }     return true;  }); 

check this: http://jsfiddle.net/5ywey/

var carvalue = $(".input-block-level").val(); 

you try select id instead of class.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -