javascript - generate alert on button click based on input type hidden -


i have html has tile view , each tile has info button. want check value of input hidden field , if value not in array defined raise alert.

html

  <div class="box" style="width:30%%">   <div class="boxinner">    <form id="form_myws" method="post">   <input type="hidden" name="state" value="%s">    <div class="titlebox">       <input type="submit" value="submit" name="ws_butt" id="submit" />     </div>    </form>   </div>   </div> 

javascript

<script type="text/javascript"> $('#submit').click(function(){     var state_list=["available","impaired","inoperable",];     var curr_state=$(this).find("input[type='hidden'][name='state']");     console.log(curr_state.val());     if (jquery.inarray(curr_state.val(),state_list)<0){             alert("submission allowed available,impaired,inoperable states.");     } }); 

it not generating alert. how achieve that?

var curr_state=$(this).find("input[type='hidden'][name='state']"); 

change

var curr_state=$(this).closest('form').find("input[type='hidden'][name='state']"); 

also add

return false; 

inside if statement won't submit form.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -