Wrox Programmer Forums
|
HTML Code Clinic Do you have some HTML code you'd like to share and get suggestions from others for tweaking or improving it? This discussion is the place.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the HTML Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 23rd, 2010, 02:37 PM
Registered User
 
Join Date: Oct 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation !Form breaking issues!

I think the best way to describe this is to show you:
Code:
	<textarea name="box" cols="110" rows="116" id="textbox">
             HERE	
             </textarea>
I need to some how enter 115 line breaks where the HERE is, but I can't figure out how to do this unless I hit enter 115 times...I don't want to do that.
 
Old October 23rd, 2010, 10:02 PM
Friend of Wrox
 
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

Inserting line breaks in your (X)HTML will be entirely ignored. Browsers reduce all blocks of whitespace in your code to a single space on the rendered page. On the up side, this is why we can indent our XHTML without regard to how we want the page to look, on the downside this means you can't add whitespace in this fashion. Also, may I ask why so many line breaks are needed? It's very likely there's a better way to solve this particular problem without the line breaks.

Technically, it is possible to accomplish something like this on the server side, and since we're dealing with form components it's unlikely that they have any purpose without a server side script to process them (non-AJAX JS apps being the lone possible exception). In a language like C#, the line breaks could be appended in code in this way. A line break is technically composed of one carriage return (unicode character U+000D) followed by a line feed (unicode character (U+000A). As long as you understand that C# allows you to escape Unicode values as a string like so, "\u000d\u000a", then you can use any Unicode codepoints, including line breaks, in your code. 99% of the time, the best practice is to use the escaped Unicode values to render the output to the page, then copy the actual glyphs as they render on the webpage and paste them into your code. This incorporates the real non-escaped content into your page relatively easily without having to adapt your keyboard. The better news is that once you have copied those characters into your code, they're easily available in the future for you to copy from that location. However, carriage returns and line feeds are automatically converted by virtually everything except a browser into a visual line break with the result that editors simply format your HTML document.

Also, unless I miss my guess, you don't actually want 115 line breaks in the textarea. What purpose is served by including that much whitespace in the form component on the webpage? This sounds like some kind of formatting that you need in the results that are returned by the form. In that case, trying to insert the line breaks into the text area is a violation of your abstractions. You don't want a text area with all that whitespace so don't put it in. On the server side, however, you do want the form output to have that formatting, so THAT'S where you add the whitespace. You'd simply do something like this.

Code:
string modifiedTextareaOutput ="";

// insert 115 line breaks
for (whitespaceCounter = 0; whitespaceCounter < 115; whitespaceCounter++)
{
     modifiedTextareaOutput += "\u000d\u000a";
}

// append the actual user input from the textarea
string actualTextareaInput = HttpContext.Current.Request["box"]; // you use the name attribute of the form component to retrieve its data

modifiedTextareaOutput += actualTextareaInput;
This allows you to keep your HTML code the way it should be while providing for the output formatting that you need to produce from the user's input.
__________________
-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Solving layout issues created by <form> tags dharmeshtandel ASP.NET 2.0 Professional 1 April 15th, 2009 09:52 AM
connection string issues, web.config file issues kaliaparijat ASP.NET 2.0 Professional 1 June 12th, 2008 08:07 AM
Regd: Issues with designing text diff form gk_sezhian C# 1 May 11th, 2008 11:30 AM
Javascript form image replacement breaking in ASP KIllfish Classic ASP Basics 0 October 2nd, 2007 08:18 AM
left join form issues?! jdtokenring Access 1 August 2nd, 2004 01:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.