i use a jquery for a input box to validate content of that
i person who has worked before me make a file that name is comoon.js and that file support all another files.but when i write this code on (document).ready(function() like this
$(document).ready(function()
{
$('#validate').keyup(function(){
var i = $('input');
(/http:\/\//).test(i.val()) && i.val(i.val().replace('http://',''));
});
});
and i have input box like this
<input type="text" id="validate" class="right" name="linkurl" maxlength="150" size="130"/>
but it doesnt work on this button what should i do and what is the problem and i know that js file loaded of all pages …
Assuming you have more than one input on your page the problem is this line:
…which sets
ito a jQuery object containing all inputs on the page. Try instead:…which will set
ito a jQuery object containing just the element the event occurred on.(Your code works when there is only one input.)
If the input in question is created dynamically after page load you’ll have a second issue: you can’t bind an event handler to an element that doesn’t exist yet, but you can use a delegated event handler:
Where ideally you’d replace
documentin$(document).on("keyup", '#validate', ...with the closest ancestor of “#validate” that exists on page load. If you’re using a version of jQuery less than 1.7 use.delegate()instead of.on()(see the jQuery API doco for more info).