Help needed to remove <br> tags in between the <input> tags.

For a particular requirement of mine, I had to create checkboxes "by hand" and add them to a panel. I could not make use of the CheckboxList control.
To ensure that each chkbox goes to a new line, I had to add a literalcontrol(<br>) after each chckbox that I added.

On rendering the chkbox section of the page has this source -

<input id="id0" type="checkbox" name="id0" /><label for="id0">ABC1</label><br>
<input id="id1" type="checkbox" name="id1" /><label for="id1">ABC2</label><br>
<input id="id2" type="checkbox" name="id2" /><label for="id2">ABC3</label><br>
<input id="id3" type="checkbox" name="id3" /><label for="id3">ABC4</label><br>
<input id="id4" type="checkbox" name="id4" /><label for="id4">ABC5</label><br>


Now on click of a client side button I delete the chkboxes that are checked, for this I loop thru the tags of type input determine the boxes tht r cheked and then delete them, this part is fine, the problem comes when I try to get rid of the <br> tags, once I determine that a chkbox needs to b deleted, how do I delete the <br> too that follows it?

Can I get the "next element" of a given element, given that I can uniquely identify the input and for tags that I need to delete. How do I uniquely identify the <br> tag that needs to go once a chkbox is removed?

In case ur wondering why I need to remove the <br>, its coz the chkboxes do not move up as the ones above r removed coz the <br>s force them to b rendered on successive lines, so there is a "void" of sorts left behind at all places where I remove the chkboxes.

Pls help me fix this, and again using a Chkboxlist is not an option.

0
QDemon19
9/24/2008 1:32:11 AM
asp.net.client-side 24353 articles. 2 followers. Follow

9 Replies
766 Views

Similar Articles

[PageSpeed] 14
Get it on Google Play
Get it on Apple App Store

What an interesting problem.

The <br /> tag can have an ID:   <br id="br1" />

Does that help?


Steve Wellens

My blog
0
SGWellens
9/24/2008 1:48:18 AM

Hi Demon try like this

 

function removeSelected()

{

 

var tg1 = document.getElementById("cbDiv").getElementsByTagName('input');

var tg2 = document.getElementById("cbDiv").getElementsByTagName('br');

for(i=0;i<tg1.length;i++)

{

if(tg1[i].checked)

{

 

 

document.getElementById("cbDiv").removeChild(tg1[i]);

document.getElementById("cbDiv").removeChild(tg2[i]);

}

}

}

<body>

<form id="form1" runat="server">

<div id="cbDiv" runat="server">

<input id="id0" type="checkbox" name="id0" /><label for="id0">ABC1</label><br>

<input id="id1" type="checkbox" name="id1" /><label for="id1">ABC2</label><br>

<input id="id2" type="checkbox" name="id2" /><label for="id2">ABC3</label><br>

<input id="id3" type="checkbox" name="id3" /><label for="id3">ABC4</label><br>

<input id="id4" type="checkbox" name="id4" /><label for="id4">ABC5</label><br> </div>

<input id="Button2" type="button" value="button" language="javascript" onclick="removeSelected()" />

 

</form> </body>

</html>

0
sivakl_2001
9/24/2008 2:35:25 AM

Without using <br> tag, it could be a solution for you

Create <span> tag around your <input>and <label> tags

<div>
<span><input id="id0" type="checkbox" name="id0" /><label for="id0">ABC1</label></span>
<span><input id="id1" type="checkbox" name="id1" /><label for="id1">ABC2</label></span>
<span><input id="id3" type="checkbox" name="id3" /><label for="id3">ABC4</label></span>
<span></span>
<span><input id="id4" type="checkbox" name="id4" /><label for="id4">ABC5</label></span>
</div>
Use Stylesheet for <span> tag
 
<style type="text/css">
span{
display:block;
}
 
 Thanks.
HOQUE MD.NAZMUL
[document.getReaders]
0
NHOQUE
9/24/2008 2:38:57 AM

SGWellens:

What an interesting problem.

The <br /> tag can have an ID:   <br id="br1" />

Does that help?

Thanks for replying.

Mayb Im asking u a very stupid question, but well I dont know abt it. I had tried in my naivety to assign an id to a Literal control but when it renders, its just a plain <br>.

Here is wat I tried doing -

for( int i = 0;i<5;i++)

{

CheckBox ckbox = new CheckBox();

ckbox.ID = "id" + i.ToString();

ckbox.Text = "ABC";ckbox.EnableViewState = true;

newPanel.Controls.Add(ckbox);

LiteralControl litctl = new LiteralControl("<br>");

litctl.ID = ckbox.ID + "lit";

newPanel.Controls.Add(litctl);

}

Is there a differnt method to assign an id to the br tag, To give u a background, I need the brs to ensure that my chkbxes render on a new line.

Thanks again.

0
QDemon19
9/24/2008 2:42:57 AM

sivakl_2001:

Hi Demon try like this

 

function removeSelected()

{

 

var tg1 = document.getElementById("cbDiv").getElementsByTagName('input');

var tg2 = document.getElementById("cbDiv").getElementsByTagName('br');

for(i=0;i<tg1.length;i++)

{

if(tg1[i].checked)

{

 

 

document.getElementById("cbDiv").removeChild(tg1[i]);

document.getElementById("cbDiv").removeChild(tg2[i]);

}

}

}

<body>

<form id="form1" runat="server">

<div id="cbDiv" runat="server">

<input id="id0" type="checkbox" name="id0" /><label for="id0">ABC1</label><br>

<input id="id1" type="checkbox" name="id1" /><label for="id1">ABC2</label><br>

<input id="id2" type="checkbox" name="id2" /><label for="id2">ABC3</label><br>

<input id="id3" type="checkbox" name="id3" /><label for="id3">ABC4</label><br>

<input id="id4" type="checkbox" name="id4" /><label for="id4">ABC5</label><br> </div>

<input id="Button2" type="button" value="button" language="javascript" onclick="removeSelected()" />

 

</form> </body> </html>

An interesting sltn - Ur banking on the fact tht the first <input> wld b tied with the first <br>, innovative indeed, let me try it, I guess it wld work by the looks of it. Thanks again!!

0
QDemon19
9/24/2008 2:48:36 AM

Have you tried my post?

If you dont want to use <br> tag, then it could be a good solution for you.

Thanks.


HOQUE MD.NAZMUL
[document.getReaders]
0
NHOQUE
9/24/2008 2:57:38 AM

NHOQUE:

Have you tried my post?

If you dont want to use <br> tag, then it could be a good solution for you.

Thanks.

Hi NHQUE,

Thnks for helping me out, well this page is in 1.1, so when it renders with the brs that I have added, it goes like this -


<span><input id="id0" type="checkbox" name="id0" /><label for="id0">ABC1</label></span><br>
<span><input id="id1" type="checkbox" name="id1" /><label for="id1">ABC2</label></span><br>
<span><input id="id2" type="checkbox" name="id2" /><label for="id2">ABC3</label></span><br>
<span><input id="id3" type="checkbox" name="id3" /><label for="id3">ABC4</label></span><br>
<span><input id="id4" type="checkbox" name="id4" /><label for="id4">ABC5</label></span><br>

Are u telling me to link this with a css tht has the property for display:block set for the span, and then it wld render on a new line w/o the brs. I did not get a chnce to test this and Im afraid I cant until tomorrow, but then if this works with the css, I will defenitely sleep better tonight :)

0
QDemon19
9/24/2008 3:12:04 AM

Yes, if you see my post, I have used CSS for <span> tag. 

Remove <br>, it is not required . As <span> tag will be handled by CSS, it is not required to <br> tag at all. Since the CSS used in the <span> tag makes its style as BLOCK.

Well, I tested it in IE as well as FF. There is no problem. Have a nice sleep tonight!

Thanks.

 


HOQUE MD.NAZMUL
[document.getReaders]
0
NHOQUE
9/24/2008 4:02:23 AM

NHOQUE:

Yes, if you see my post, I have used CSS for <span> tag. 

Remove <br>, it is not required . As <span> tag will be handled by CSS, it is not required to <br> tag at all. Since the CSS used in the <span> tag makes its style as BLOCK.

Well, I tested it in IE as well as FF. There is no problem. Have a nice sleep tonight!

Thanks.

 

Bravo IT WORKS :) THNX A TON..a simple sltn to this messy problem.

0
QDemon19
9/24/2008 4:22:11 PM
Reply:

Similar Artilces:

How to remove <p> and <b> and <i> tags
Hi, I have some text in the database which has Html tags. I want that when I display the data the tags are removed.HighOnCodingWanna get high! You might consider called Server.HtmlEncode(data) on the rows to convert the html to characters that will be displayed in the browser.--Brian DesmondWindows Server MVP - Directory Serviceshttp://www.briandesmond.com Hi, Thanks for the Quick reply. Well now its displaying something like this: " &lt;P&gt;&lt;P&gt; &lt;i&gt;&lt;P&gt;if( dr.Read())&lt;P&gt;&lt;P&gt;{&lt;P&am...

How to strip a string of <html>, ,</html>, <body>, </body>, <form ... >, </form> tags?
I have stream which is the HTML input of a page. Now I want to use only that part of this page, that is within <form .....> and </form> tags, and excluding these tags.How would I go about stripping <html>, ,</html>, <body>, </body>, <form ... >, </form>, <head> and </head> tags? I have to make sure that <head ...javascript..> and its corresponding </head> tags are not stripped in this process.sun21170    Wait... you said you wanted to strip the head tags, and you're also saying you need to NOT strip the ...

Adding run-time created <li></li> tags inbetween <ul>/ul> tags
I want to create a custom control which will create a unordered list and fill it with list items of which will be created at run-time. Currently I am using the following logic: At my Default.aspx page:<ai:ul_adder ID="ul_adder1" ListItemString="Page1 1,sf1.aspx,image/edit.gif; Page 2,sf2.aspx,image/colaps.gif" runat="server"/>and at the ul_adder.ascx file 1 public string ListItemString 2 { 3 set 4 { 5 string[] itemlist = value.Split(';'); 6 7 for (int i = 0; i < itemlist.Length; i++) 8 ...

Bug rendering <p> tags around <pre> or <code> tags
Name: Tim Robinson Email: tcr1272atgmaildotcom Product: Firefox Summary: Bug rendering <p> tags around <pre> or <code> tags Comments: Two Examples below, both render the <p> tags differently and incorrectly. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <body> <p> <pre> <div> my text </div> </pre> <p> <body> <html> <!DOCTYP...

Programmatically Add <BR> tag between <IMG> tags in cell
Here is my sample code: Dim table As Table Dim row As TableRow Dim cell As TableCell Dim myImage As HtmlImage Dim myBreak As New HtmlGenericControl("br") cell.Width = Unit.Pixel(1) myImage = New HtmlImage myImage.Height = 26 myImage.Width = 1 myImage.Src = "../Images/spacer.gif" cell.Controls.Add(myImage) cell.Controls.Add(myBreak) myImage = New HtmlImage myImage.Height = 1 myImage.Width = 1 myImage.Src = "../Images/666699.gif" cell.Controls.Add(myImage) row.Controls.Add(cellDivider) table.Rows.Add(row) ...

Encoding <br> and <p> tags for text input
Hello all, I am making a form where a user can type an article and submit it to a database. (Access) However, I cannot include line breaks or paragraphs. The text all runs together. I believe I can use the HtmlEncode function to remedy this. Also setting ValidateRequest to "False". Can someone help me with the syntax code for this in VB.NET? I think it is something like this: Dim sb as StringBuilder = new StringBuilder( HttpUtility.HtmlEncode(htmlInputTxt.Text)); sb.Replace("&lt;b&gt;", "<br>") Response.Write(sb.ToString()) Pleas...

Inline tags...<%=%>, <%# %>, <%$ %> ....etc...
I come from a classic ASP background, so I know what <%= [string] %> means...but what about:  <%# expression %> and <%$ expression %>  --------------- I've seen <%# expression %> used mainly in databinding (<%# Bind("employeename") %>) for a TemplateField but am not sure exactly what it means (though I know what it does). I would think that <%= and <%# are synonymous but it seems they are not. <%$ expression %> I've only seen in an SqlDataSource when setting the ConnectionString attribute to: <%$ ConnectionStri...

Need Help With <form runat=server></form> Tags
Hello everyone I have a real newbie question for anyone that wants to help me out...... I am creating a e-commerce website right now (yes a massive project for me) and I am having this problem. I have set up my site with a master page and then the content pages. On my master page I have a login view and inside that login view I have a login name <asp:LoginName ID="LoginName1" runat="server"> I just draged and dropped it so when my users are signed in they can see a welcome message... this login name requires a <form runat=server> Tag in which I've placed in it....(this works ...

superreview requested: [Bug 238989] whitespace after a </b> tag is ignored when enclosed inside <fieldset></fieldset> tags : [Attachment 145302] This should fix it
Boris Zbarsky <bzbarsky@mit.edu> has asked Peter Van der Beken <peterv@propagandism.org> for superreview: Bug 238989: whitespace after a </b> tag is ignored when enclosed inside <fieldset></fieldset> tags http://bugzilla.mozilla.org/show_bug.cgi?id=238989 Attachment 145302: This should fix it http://bugzilla.mozilla.org/attachment.cgi?id=145302&action=edit ------- Additional Comments from Boris Zbarsky <bzbarsky@mit.edu> So the problem here was that <fieldset> was marked as a tag which is allowed to discard all direct child whitespace...

superreview granted: [Bug 238989] whitespace after a </b> tag is ignored when enclosed inside <fieldset></fieldset> tags : [Attachment 145302] This should fix it
Peter Van der Beken <peterv@propagandism.org> has granted Boris Zbarsky <bzbarsky@mit.edu>'s request for superreview: Bug 238989: whitespace after a </b> tag is ignored when enclosed inside <fieldset></fieldset> tags http://bugzilla.mozilla.org/show_bug.cgi?id=238989 Attachment 145302: This should fix it http://bugzilla.mozilla.org/attachment.cgi?id=145302&action=edit ------- Additional Comments from Peter Van der Beken <peterv@propagandism.org> Fine by me, although I don't really understand why we'd want kOmitWS at all. ...

Should the <title> tag go into the <ContentPlaceHolder> tag?
In VS 2008, I want to be able to easily edit the <title> tag in a child page that inherits from a master page.  When I create the .master page it places the <title> tag outside of the <ContentPlaceHolder> tag in the header section.  Should I move it into that <ContentPlaceHolder> tag in the header section?  Doctor Who If you're trying to set the title of the page based on the content page you can use,Page.Header.Title = "<Page Title>in your content page code.Refer to this link for more information.http://aspnet.4guysfromrolla.com/artic...

Difference between <location> tag and <authorization> tag?
 Hello,Both these tags control what a user can do, then what is the difference.? <authorization> <allow roles="Administrator,CanEdit" /> <deny users="*" /></authorization><location path="ADMIN">    <system.web>      <authorization>        <allow roles="ADMIN"/>        <deny users="*"/>      </authorizat...

>>>> Heads up <<<<
I just got a warning from Norton that "PamelaSetup-Basic.exe" has a virus in it. The name is "VirusBurst" Luckily, I did not install this software and Norton's quarantined it so I could delte it, which I have done. Symantec has not completed analysis of this particular piece of garbage but it did catch the sig. If you have installed Pamela, you may be in trouble. Duffy wrote: > I just got a warning from Norton that "PamelaSetup-Basic.exe" has a virus > in it. The name is "VirusBurst" > > Luckily, I did not install...

superreview requested: [Bug 302729] netError.dtd entities can't be formatted prettily : [Attachment 193230] Convert [tag][/tag] in error strings to <tag></tag>
Jeff Walden (remove +bmo to email) <jwalden+bmo@mit.edu> has asked Darin Fisher (on vacation 8/13 - 8/28) <darin@meer.net> for superreview: Bug 302729: netError.dtd entities can't be formatted prettily https://bugzilla.mozilla.org/show_bug.cgi?id=302729 Attachment 193230: Convert [tag][/tag] in error strings to <tag></tag> https://bugzilla.mozilla.org/attachment.cgi?id=193230&action=edit ...

Web resources about - Help needed to remove <br> tags in between the <input> tags. - asp.net.client-side

Resources last updated: 12/24/2015 3:08:49 PM