Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RegExp and getElementById 1

Status
Not open for further replies.

mdjoin

Programmer
Jun 22, 2007
9
US
Hey all,

I've been searching for a whlie for the solution to this, and its driving me nuts.

I need to know if its possible to use Regular Expressions to search for a partial match with "getElementById" - I know for a fact that: document.getElementById('(.)*myTextBox');

Will not find something with the id of: _123_myTextBox - even though it is a valid expression.

Anyone know another way to do this quick and effectively?
 
Not that I know although some javascript libraries such as jquery might have this functionality.

I would opt for the option to make my own.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
<script language="JavaScript">
	function regexidsearch(regex){

		var inputs = document.getElementsByTagName('input');
		for(var i=0; i< inputs.length; i++){
			var str = inputs[i].id;
			if (str.match(regex).length){
				alert(str);
			}
		}
	}
</script>
<body onload="">

	<input type="text" id=" _123_myTextBox" value=""><br>
	<input type="text" id=" _1234_myTextBoxt" value=""><br>
	<input type="text" id=" _12345_myTextBox" value=""><br>
	<input type="text" id=" _123_myTaxtBox" value=""><br>
<br><br><br>

	input regex:<input type="text" id="regex">	<button onclick="regexidsearch(document.getElementById('regex').value);">test</button>
</form>
 </body>
</HTML>

See how this example works and get an idea. If you really wanna get into it make your own prototype and extend the document to include a regex search tags.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top