Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

Form validation with jquery - return false -


can 1 tell why folowing code doesn't work. alerts should. return true afterwards, if field empty.

<form id="theform" method="post" action="mailme.php"> <input id="field1" name="a" value="field1" type="text" /> <input id="field2" name="b" value="field2" type="text" /> <input id="field3" name="c" value="field3" type="text" /> <input id="field4" name="d" value="field4" type="text" />  <input type="submit" /> </form> <script> $('#theform').submit(function(){     $('#theform input[type=text]').each(function(n,element){         if ($(element).val()=='') {              alert('the ' + element.id+' must have value');              return false;         }     });     return true; });  </script> 

you can use jquery's filter() function callback function, , testing resulting array size, returning true if it's zero.

$('#theform').submit(function(event) {   var filtered = $('#theform input[type=text]').filter(function(index) {     if ($(this).val() == '') {       alert('the ' + this.id + ' must have value');        return true;     }      return false;   });    return filtered.length == 0; }); 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -