Solved

Help with formatting a web form (HTML)

Posted on 2007-11-14
5
195 Views
Last Modified: 2010-04-09
Hi

I need help formatting a form on a website (not done forms before).  I basically want the questions to appear on the left and the input boxes to appear on the right (in the same position down the page).  Some of the questions may be a few sentences long so the input box on the right would need to be in line with the top of the first line of the question.  I know this is easy but I'm not experienced in forms or formatting and I haven't got time to work it out as I'm meant to be working on the content!  Therefore 500 points.  Any extra coding to make the form look smarter such as a box etc would be appreciated.  Cheers.  

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>

.labeltxt {margin-right:10px; width:190px; background-image:none}
.row {width:420px; margin-left:10px; background-image:none}
</style>
</head>
<body>

<form action="cover_calculator_process.do" method="post">
<h3>FORM</h3>
      
<div class="row">                         
<label for="val1">
<span class="labeltxt">Question 1: XXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXX</span>
<input id="val1" name="val1" class="calc" type="text" value="" />
</label>
</div>
            
<div class="row">                         
<label for="val2">
<span class="labeltxt">Question2: XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXX</span>
<input id="val2" name="val2" class="calc" type="text" value="" />
</label>
</div>
                  
<div class="row">                         
<label for="val3">
<span class="labeltxt">Question 3: XXXXXXXXXXXXXXXXXXXXXXXXXXXX</span>
<input id="val3" name="val3" class="calc" type="text" value="" />
                   
<div class="row">                         
<label for="val4">
<span class="labeltxt">Question 4: XXXXXXXXXXXXXXXXXXXXXXXXXXXX</span>
<input id="val4" name="val4" class="calc" type="text" value="" />        
</label>
</div>
                  
<div class="row">
<input class="button" type="submit" name="calculate" value="Calculate" />
</div>
</form>
                    
</body>
</html>
0
Comment
Question by:dvsuk
5 Comments
 
LVL 18

Expert Comment

by:Eternal_Student
ID: 20280015
You mean something like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.row{width:600px; clear:both; border:1px dotted #f1f1f1; margin:4px 0; padding:4px;}
label{float:left; width:250px; }
.row {width:420px; margin-left:10px; background-image:none}
.calc{float:left; margin-top:6px;}
.button{float:right; margin-right:10px;}
</style>
</head>
<body>

<form action="cover_calculator_process.do" method="post">
<h3>FORM</h3>
     
<div class="row">                        
<label for="val1">
<span class="labeltxt">Question 1: How many questions can be asked in one form for example?</span>
</label>
<input id="val1" name="val1" class="calc" type="text" value="" />
</div>
           
<div class="row">                        
<label for="val2">
<span class="labeltxt">Question2: Less text?</span>
</label>
<input id="val2" name="val2" class="calc" type="text" value="" />
</div>
                 
<div class="row">                        
<label for="val3">
<span class="labeltxt">Question 3: How many questions can be asked in one form for example?</span>
</label>
<input id="val3" name="val3" class="calc" type="text" value="" />
</div>
                   
<div class="row">                        
<label for="val4">
<span class="labeltxt">Question 4: How many questions can be asked in one form for example?</span>
</label>
<input id="val4" name="val4" class="calc" type="text" value="" />        
</div>
                 
<div class="row">
<input class="button" type="submit" name="calculate" value="Calculate" />
</div>
</form>
                   
</body>
</html>
0
 
LVL 18

Accepted Solution

by:
Eternal_Student earned 500 total points
ID: 20280051
This better:

You can play around with the width values and styling I have just laid it out nicely.

========================
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.row{width:600px; clear:both; border:1px dotted #f1f1f1; margin:4px 0; padding:4px;}
label{float:left; width:250px; }
.row {width:420px; margin-left:10px; background-image:none}
.calc{float:left; margin-top:6px; }
.button{float:right; margin-right:10px;}
.clear{clear:both;}
</style>
</head>
<body>

<form action="cover_calculator_process.do" method="post">
<h3>FORM</h3>
     
<div class="row">                        
<label for="val1">
<span class="labeltxt">Question 1: How many questions can be asked in one form for example?</span>
</label>
<input id="val1" name="val1" class="calc" type="text" value="" />
<br class="clear" />
</div>
           
<div class="row">                        
<label for="val2">
<span class="labeltxt">Question2: Less text?</span>
</label>
<input id="val2" name="val2" class="calc" type="text" value="" />
<br class="clear" />
</div>
                 
<div class="row">                        
<label for="val3">
<span class="labeltxt">Question 3: How many questions can be asked in one form for example?</span>
</label>
<input id="val3" name="val3" class="calc" type="text" value="" />
<br class="clear" />
</div>
                   
<div class="row">                        
<label for="val4">
<span class="labeltxt">Question 4: How many questions can be asked in one form for example?</span>
</label>
<input id="val4" name="val4" class="calc" type="text" value="" />    
<br class="clear" />    
</div>
                 
<div class="row">
<input class="button" type="submit" name="calculate" value="Calculate" />
<br class="clear" />
</div>
</form>
                   
</body>
</html>
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 20280094
Just beat me to it!
Here's another take - note that you have an error in your code where you miss closing a label and div...


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title>
<style type="text/css">
      .row {width:420px; margin-left:10px; position:relative; background-color:#eeeeee; margin-bottom:20px; padding:5px;}
      .row label {padding-right:160px; display:block;}
      .row input {position:absolute; right:0; top:0; width:150px; margin:5px;}
      .row .labeltxt {margin-right:10px;}
</style>
</head>
<body>
      <form action="cover_calculator_process.do" method="post">
            <h3>FORM</h3>
            
            <div class="row">
                  <label for="val1">
                        <span class="labeltxt">Question 1: XXXXXXXX XXXXXXXXX XXXXXX XXXXX XXXX XXXXX XXXXX XXX XXXXXXX</span>
                        <input id="val1" name="val1" class="calc" type="text" value="" />
                  </label>
            </div>
            <div class="row">
                  <label for="val2">
                        <span class="labeltxt">Question2: XXXXX XXXXXX XXXX XXXXXX XXXX XXXXXXXX XXXX XXXX XXXX XXXXXXXX</span>
                        <input id="val2" name="val2" class="calc" type="text" value="" />
                  </label>
            </div>
            <div class="row">
                  <label for="val3">
                        <span class="labeltxt">Question 3: XX XXXXX XXX XXXXX XXXXXX XXXXXXX</span>
                        <input id="val3" name="val3" class="calc" type="text" value="" />
                  </label>
            </div>
            <div class="row">
                  <label for="val4">
                        <span class="labeltxt">Question 4: XXXXXXXX XXX XXXXXXXX XXX XXXXXX</span>
                        <input id="val4" name="val4" class="calc" type="text" value="" />
                  </label>
            </div>
            <div class="row">
                  <input class="button" type="submit" name="calculate" value="Calculate" />
                  <div style="clear:both;">&nbsp;</div>
            </div>
      </form>
</body>
</html>
0
 
LVL 16

Expert Comment

by:rbudj
ID: 20280168
0
 

Author Comment

by:dvsuk
ID: 20280211
Thanks Eternal Student and Rouchie for your help.  Really good link rbudj - will be useful for other projects - thanks for that.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now