0

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

2
Contributors
4
Replies
10
Views
6 Years
Discussion Span
Last Post by Buppy
0

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

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

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?

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

I think this should work.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.