• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

Help with formatting a web form (HTML)

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
dvsuk
Asked:
dvsuk
1 Solution
 
Eternal_StudentCommented:
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
 
Eternal_StudentCommented:
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
 
RouchieCommented:
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
 
rbudjCommented:
0
 
dvsukAuthor Commented:
Thanks Eternal Student and Rouchie for your help.  Really good link rbudj - will be useful for other projects - thanks for that.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now