473,401 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

getting document elements by regular expressions

Hi All,

I need to fetch a document-element but i do not know the full Id of the element.
I only know part of the id of the element. Is it possible to get something like "Give me the element which has id starting with XXXXX".

Say we have 3 elements
1)<input type="text" id="My_name_is_ABC value="textboxval">
2)<input type="text" id="My_name_is_BEF value="textboxval">
3)<input type="text" id="My_name_is_YEX value="textboxval">

now , in my script i have only "My_name_is_A" and i want to get a reference of an object whose id starts with "My_name_is_A".
Is it possible to do so ?
Can i use something like
var regularExp = new RegExp("My_name_is_A");
document.getElementById(regularExp);

Of course the above does not work :(
Jun 27 '07 #1
2 1395
mrhoo
428 256MB
id="My_name_is_ABC value="textboxval">

It will never work unless you close the quotes for the id value.

id="My_name_is_ABC" value="textboxval">
Jun 27 '07 #2
Logician
210 100+
Hi All,

I need to fetch a document-element but i do not know the full Id of the element.
I only know part of the id of the element. Is it possible to get something like "Give me the element which has id starting with XXXXX".
There could be more than one element with an id starting with that prefix. This will return a reference to the first one found:
Expand|Select|Wrap|Line Numbers
  1. function getFirstElementWithIDPrefix( prefix )
  2. {
  3.  var allElems=document.getElementsByTagName('*');
  4.  
  5.  for( var i=0; i<allElems.length && allElems[i].id.indexOf(prefix); i++)
  6.  ;
  7.  
  8.  return (i==allElems.length) ? null : allElems[i];
  9. }
Jun 27 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
3
by: Edwin G. Castro | last post by:
Hi, I'm new to XSLT and I'm having a hard time figuring out whether XSLT will do what I need it to do. I have a XML file with a whole bunch of <message> elements. These <message> elements...
1
by: Cognizance | last post by:
Hi gang, I'm an ASP developer by trade, but I've had to create client side scripts with JavaScript many times in the past. Simple things, like validating form elements and such. Now I've been...
2
by: Sehboo | last post by:
Hi, I have several regular expressions that I need to run against documents. Is it possible to combine several expressions in one expression in Regex object. So that it is faster, or will I...
4
by: Együd Csaba | last post by:
Hi All, I'd like to "compress" the following two filter expressions into one - assuming that it makes sense regarding query execution performance. .... where (adate LIKE "2004.01.10 __:30" or...
22
by: gabon | last post by:
Hi guys, I'm facing the bug about the failure of innterHTML while reading xhtml content inside a DIV, in fact it has passed as html removing the closing of some nodes. Is there a way to read the...
3
by: a | last post by:
I'm a newbie needing to use some Regular Expressions in PHP. Can I safely use the results of my tests using 'The Regex Coach' (http://www.weitz.de/regex-coach/index.html) Are the Regular...
1
by: Jo M | last post by:
Hello, Does anyone of you know any tool that would convert regular expressions to XML compatible form? I mean tool that would convert e.g. & to &amp; etc. I have written an ASP.NET C#...
1
by: Allan Ebdrup | last post by:
I have a dynamic list of regular expressions, the expressions don't change very often but they can change. And I have a single string that I want to match the regular expressions against and find...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.