Hello,

I have a script that prints out a lot of <tr>'s, each has a different id, let's say it's a number. What i am trying to get is when a user enters numbers in a certain textfield, named #idtext for example, it shows only those <tr>'s whose id numbers matches the entered value and hides the rest. For example, user enters 23 in the text field, rows with id numbers 123, 23, 231 are shown, the rest are hidden, etc.

Atm i have smoething like this, not working:

$("#idtext").change(function(){	
		var val = $("#idtext").val();
		$('tr[id^<>'+val+']').hide();		
		$('tr[id^='+val+']').show();		
	});

Thanks

Give class 'alltr' to all tr.
And then try below code.

$("#idtext").change(function(){			
		$('.alltr').hide();		
		$('#'+$("#idtext").val()).show();		
});

Thanks, however, i need it to show also partially matching id's. I think i should use regular expressions:

$("#idtext").change(function(){
		$('.alltr').hide();
		var regexpm = new RegExp($("#idtext").val());
		$('id').match(regexpm).show();
    });

The above code does not work, i guess there's something wrong with the RegExp and variable value. Any ideas?

$("#idtext").change(function(){			
		$('.alltr').hide();		
		$('div[id*="'+$("#idtext").val()+'"]').show();	
});

I think this should work.

Thanks, works.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.