Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery disable old function and execute new function on select box change
    primarykey
    data
    text
    <p>I have two functions</p> <p>first</p> <pre><code>function normal_validate() { $("#add_expense").validate({ rules : { expense : { required : true }, category : { required : true } }, submitHandler : function(form) { $.post('add/add_expense_result.php', $("#add_expense").serialize(), function(data) { $('#add_expense .message_outer').fadeIn('slow').html(data).delay(3000).fadeOut('slow'); }); $('#add_expense')[0].reset(); var first_category = $('#categories option:nth-child(1)').text(); $('#add_expense .customSelectInner').html(first_category); return false; } }); } </code></pre> <p>second</p> <pre><code>function advanced_validate() { $("#add_expense").validate({ rules : { expense : { required : true }, category : { required : true }, customer_name : { required : true, minlength : 3 }, customer_email : { email : true }, customer_address : { required : true, minlength : 5 } }, submitHandler : function(form) { // do other stuff for a valid form $.post('add/add_expense_result.php', $("#add_expense").serialize(), function(data) { $('#add_expense .message_outer').fadeIn('slow').html(data).delay(3000).fadeOut('slow'); }); $('#add_expense')[0].reset(); var first_category = $('#categories option:nth-child(1)').text(); $('#add_expense .customSelectInner').html(first_category); var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ"; var string_length = 5; var result = ""; for (var i = 0; i &lt; string_length; i++) { var randomPos = Math.floor(Math.random() * chars.length); result += chars.substr(randomPos, 1); } $('input.customerCode').val(result); return false; } }); $('.existingcustomer').autocomplete({ source : 'suggest/suggest_customer.php', select : function(event, ui) { $('.customerId').val(ui.item.id); $('.customerCode').val(ui.item.code); $('.customerName').val(ui.item.name); $('.customerEmail').val(ui.item.email); $('.customerPhone').val(ui.item.phone); $('.customerAddress').val(ui.item.address); return false; }, }).data("autocomplete")._renderItem = function(ul, item) { return $("&lt;li&gt;&lt;/li&gt;").data("item.autocomplete", item).append("&lt;a&gt;" + item.name + " - " + item.address + "&lt;/a&gt;").appendTo(ul); }; $(".existingCustomer").live("click", function() { $('input.customerName').removeClass('newcustomer'); $('input.customerName').addClass('existingcustomer'); $('input.customerCode').removeClass('newId'); $('input.customerCode').addClass('oldId'); $('.newCustomer').attr('checked', false); $('#customer_details input').val(''); $('#customer_details textarea').val(''); $(".existingcustomer").autocomplete("enable"); }) $(".newCustomer").live("click", function() { $('input.customerName').removeClass('existingcustomer'); $('input.customerName').addClass('newcustomer'); $('input.customerCode').removeClass('oldId'); $('input.customerCode').addClass('newId'); $('.existingCustomer').attr('checked', false); $('#customer_details input').val(''); $('#customer_details textarea').val(''); $('input.newId').val(result); $(".newcustomer").autocomplete("disable"); }); } </code></pre> <p>i want normal_validate function on document ready. after my select box change , i want change function.</p> <p>html</p> <pre><code>&lt;form action="" method="post" id="add_expense"&gt; &lt;section class="widget mb20 border"&gt; &lt;h4 class="title"&gt;Expense Details &lt;span class="info"&gt;(*) fields are mandatory&lt;/span&gt;&lt;/h4&gt; &lt;div class="inner_content"&gt; &lt;div class="left"&gt; &lt;p&gt; &lt;label&gt;Expense * (&lt;?php echo $currency; ?&gt;)&lt;/label&gt; &lt;input type="text" name="expense" class="text" /&gt; &lt;br class="clear" /&gt; &lt;/p&gt; &lt;p class="category"&gt; &lt;label&gt;Category&lt;/label&gt; &lt;span class="select"&gt; &lt;select name="category" id="categories"&gt; &lt;option value=""&gt;Choose an option&lt;/option&gt; &lt;?php if ($expense_categories !== FALSE &amp;&amp; mysql_num_rows($expense_categories) &gt; 0) { while ($row = mysql_fetch_array($expense_categories)) { $category = $row['category_name']; ?&gt; &lt;option&gt;&lt;?php echo $category; ?&gt;&lt;/option&gt; &lt;?php } } ?&gt; &lt;/select&gt; &lt;span class="add_category"&gt; new&lt;/span&gt; &lt;/span&gt; &lt;br class="clear" /&gt; &lt;/p&gt; &lt;/div&gt; &lt;div class="right"&gt; &lt;p class="mbn"&gt; &lt;label&gt;Description&lt;/label&gt; &lt;textarea name="description" cols="30" rows="10"&gt;&lt;/textarea&gt; &lt;br class="clear" /&gt; &lt;/p&gt; &lt;input class="created_by text hidden" type="text" readonly name="created_by" value="&lt;?php echo $user_id; ?&gt;"/&gt; &lt;/div&gt; &lt;br class="clear" /&gt; &lt;/div&gt; &lt;/section&gt;&lt;!--(main content content_inner widget(create_invoice))--&gt; &lt;section class="widget col2 left border mb20 hidden" id="customer_details"&gt; &lt;h4 class="title"&gt;Customer Details&lt;/h4&gt; &lt;div id="customer_type"&gt; &lt;span class="exist"&gt; &lt;input type="checkbox" name="existing_customer" class="existingCustomer" checked="true"/&gt; &lt;label &gt;Existing Customer&lt;/label&gt; &lt;/span&gt; &lt;span class="new"&gt; &lt;input type="checkbox" name="new_customer" class="newCustomer"/&gt; &lt;label &gt;New Customer&lt;/label&gt; &lt;/span&gt; &lt;/div&gt; &lt;div class="inner_content"&gt; &lt;p&gt; &lt;label&gt;Name *&lt;/label&gt; &lt;input type="text" name="customer_name" class="customerName existingcustomer text"/&gt; &lt;br class="clear" /&gt; &lt;/p&gt; &lt;p&gt; &lt;label&gt;Address *&lt;/label&gt; &lt;textarea name="customer_address" cols="30" rows="10" class="customerAddress"&gt;&lt;/textarea&gt; &lt;br class="clear" /&gt; &lt;/p&gt; &lt;p&gt; &lt;label&gt;Phone&lt;/label&gt; &lt;input type="text" name="customer_phone" class="customerPhone number"/&gt; &lt;br class="clear" /&gt; &lt;/p&gt; &lt;p class="hidden"&gt; &lt;input type="text" name="customer_id" readonly class="customerId text " /&gt; &lt;input class="customerCode" type='text' name='customer_code' value=""/&gt; &lt;br class="clear" /&gt; &lt;/p&gt; &lt;p class="mbn"&gt; &lt;label&gt;Email&lt;/label&gt; &lt;input type="text" name="customer_email" class="customerEmail text"/&gt; &lt;br class="clear" /&gt; &lt;/p&gt; &lt;/div&gt; &lt;/section&gt;&lt;!--(widget orange customer_details_widget)--&gt; &lt;br class="clear" /&gt; &lt;section class="submit_area"&gt; &lt;input type="submit" class="submit" value="Ready to go!"/&gt; &lt;span class="message_outer"&gt;&lt;/span&gt; &lt;/section&gt; &lt;/form&gt; </code></pre> <p>jquery</p> <pre><code>jQuery(document).ready(function() { normal_validate(); $('#categories').change(function() { var value = $(this).val(); if (value == 'repayment' || value == 'credit') { $('#customer_details').show(); //i want disable normal_validate function advanced_validate(); } else { $('#customer_details').hide(); //i want disable advanced_validate function normal_validate(); } if (value == 'repayment') { $('#customer_details .new').hide(); } else { $('#customer_details .new').show(); } }); }); </code></pre> <p>my problem is after select box value change to credit or repayment, still working normal_validate function. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload