473,785 Members | 2,801 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript problem

Hello, can any body help me out..

I have some td element which have following ids
ctl1_lnkPrint
ctl2_lnkPrint
ctl3_lnkPrint
ctl4_lnkPrint
ctl5_lnkPrint
...
...
...

and i just know the "lnkPrint", so i have to use wildcard characters...
(something like *lnkPrint)

I want to trap all TD elements with the above sequence id from the html
document (using getElementbyID. ...) and replace those td element with
blank td element...

Can anybody give me javascript of above scenario....

Thanks in Advance
Meehir

Jul 23 '05 #1
4 2690
me********@gmai l.com wrote:
Hello, can any body help me out..

I have some td element which have following ids
ctl1_lnkPrint
ctl2_lnkPrint
ctl3_lnkPrint
ctl4_lnkPrint
ctl5_lnkPrint
..
..
..

and i just know the "lnkPrint", so i have to use wildcard characters...
(something like *lnkPrint)

I want to trap all TD elements with the above sequence id from the html
document (using getElementbyID. ...) and replace those td element with
blank td element...

Can anybody give me javascript of above scenario....

Thanks in Advance
Meehir

Meehir

Those Id's look very asp.net to me!

It's possible to write those Id's to a javascript var from your
codebehind. As this is a javascript group I will not go into too much
detail. As a side note this is one of the reasons i stopped using
asp.net.

----------------- C# CODE -----------------

string cJavascript = "var aIDs = [";

// at this point you need to cycle through your Serverside objects and
// using their .ClientID attrib build a string that represents a
// javascript array. i.e. "var cIDs = ['foo', 'bar'];"

// Then add it to the page
this.Page.Regis terClientScript Block("uniqueSe rverSideKey", "<script
type=\"text/javascript\">" + cJavascript + "</script>");

-------------------------------------------

This will add the array to the page. So you could cycle through the
array to obtain your elemnts.

----------------- JS CODE -----------------

for( var i = 0; i < aIDs.length; i++ )
{
var eElement = document.getEle mentById(aIDs[i]);
}

-------------------------------------------
Having said that it is possible to obtain it them using just javascript.

If the containing table has an ID that you know you could use :

var etable = document.getEle mentsById("IdOf Table");
var aCells = etable.getEleme ntsByTagName("t d");

This will then return ALL the cells of the table that you can apply
logic to in order to ensure you have the correct elements and then to do
what you want with them.

HTH

Andy
Jul 23 '05 #2
Hi Andy,

I am not 100% satisfied with ur solution,
as i have mentioned that i dont know the exact id of td element.

I just know later part of id in advance (eg. lnkPrint of ctl2_lnkPrint)
and i want to scan the innerhtml part of some document through the loop
and find those td element with lnkPrint as suffix.

As I cant use server side code, so i dont take any benefit of ur
solution of C#.

Actual scenario is:
--------------------
i am navigating from page1 to page2, in page2 i am showing some html
section of page1 in page2 by
lblData.innerht ml = window.document .getelementbyid (id).innerhtml

But out of this html, i dont want to display some td element with
lnkPrint as suffix.

For that, i want to scan the innerhtml part of that document through a
loop and find those td element with lnkPrint as suffix.

Jul 23 '05 #3
me********@gmai l.com wrote:
i am navigating from page1 to page2, in page2 i am showing some html
section of page1 in page2 by
lblData.innerht ml = window.document .getelementbyid (id).innerhtml
This looks strange, the syntax isn't correct and suggests you get your
data from the same page and not from different documents. Are you using
frames? If not how do you import the nodes from the first document?
But out of this html, i dont want to display some td element with
lnkPrint as suffix.

For that, i want to scan the innerhtml part of that document through a
loop and find those td element with lnkPrint as suffix.


I'm not sure to have understood your scenario, but check whether the
following does help you - it exemplifies some DOM methods (replaceChild,
getElementsByTa gName, createElement) and introduces a regexp to find the
elements you're looking for.
---
<style type="text/css">
table {
border:thin #dd8 groove;
}
td {
margin:1px;
background-color:#ffc;
border: solid 1px #dd8;
font-family:Garamond ;
width:3em;
height:3em;
text-align:center;
}
td:hover {
border: solid 1px yellow;
}
</style>

<table>
<tbody>
<tr>
<td id="1_lnkPrint" >Luffy</td>
<td id="2_lnkPrint" >Zoro</td>
</tr>
<tr>
<td id="3_foo">Nami </td>
<td id="4_lnkPrint" >Sanji</td>
</tr>
</tbody>
</table>

<form action="foo">
<input type="button" value="foo()" onclick="foo()" >
</form>

<script type="text/javascript">
function foo(){
if(
document.create Element &&
document.getEle mentsByTagName &&
document.replac eChild
){

var td=document.get ElementsByTagNa me("td"); // or another container
for(var ii=td.length; ii--;) {
if(/lnkPrint$/i.test(td[ii].id)) {
td[ii].parentNode.rep laceChild(
document.create Element("td"),
td[ii]
);
}
}

}
}
</script>
---
HTH
Yep.
Jul 23 '05 #4
If you manipulate members of a nodelist, their indexes can change to reflect
the new order.
Get an array of elements that fit the id "closeness" test;
then do whatever to each of the elements in the array.
in your example str is a regular expression: /ctl(\d+)_lnkPri nt/;
tag is 'td';

function nearEnough(str, tag){
var A= document.getEle mentsByTagName( tag);
var X= new Array();
var L= A.length;

for(var i= 0; i< L; ;i++){
var who= A[i];
var tem= who.id;
if(tem && str.test(tem)) X.push(who) ;
}
return X;
}
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
9460
by: Kai Grossjohann | last post by:
It seems that Ctrl-N in Mozilla opens a new empty browser window. That's fine, I don't need to do anything about it. But Ctrl-N in IE appears to clone the current window. Is there a way to intercept the key so that I can do stuff on the server side to make the new window behave correctly? (We have a JSP-based webapp which stores state in the session. Now if two windows access (and modify!) the same session, then madness will result....
53
5746
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is difficult to know what is going on. One of these Order Forms you can see here... http://www.cardman.co.uk/orderform.php3
6
2281
by: Alex Rast | last post by:
First of all, this is not a programming question. I'm a user, not programming in JavaScript. I'm not, however, a novice user or even a power user - I certainly know programming intimately as well as computer hardware, configuration, etc... down to the lowest level (e.g. BIOS, assembly language, etc). Anyway, I've obviously got something wrong with JavaScript configuration, files, etc. in Windows 2000, Service Pack 3, because on sites...
136
9457
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to use. The above URL is version 1.0 (draft) that resulted. IMO, it is not a replacement for the FAQ,...
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9481
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10155
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10095
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3655
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.