2

I've been working on this JavaScript table and I'm stuck. I tried to find an answer here and on the web but unfortunately I couldn't.

What am I trying to do is align all the text fields and bring as close as I can the comments textbox.

<html>
<body>
<table cellspacing= "20px">
<tr><td></td><td></td><td rowspan="6" valign="top">Comments
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br><textarea rows="4" cols="40" name="Comments" tabindex="6"></textarea></td></tr>
<tr><td>Your&nbsp;Name*</td><td><input name="Name" id="Name" tabindex="1"></td><td></td></tr>
<tr><td>Company</td><td><input name="Company" id="Company" tabindex="2"></td></tr>
<tr><td>E-mail*</td><td><input name="Email" id="Email" tabindex="3"></td></tr>
<tr><td>Telephone*</td><td><input name="Phone" id="Phone" tabindex="4"></td></tr>
<tr><td>Your Partner name</td>
<td><input name="Partner" id="Partner" tabindex="5"></td>
<td>This is a text and it suppose to be long. Actually exactly this length.</td></tr>
</table>

</body>
</html>

Everything works great until I add the line:

<td>This is a text and it suppose to be long. Actually exactly this length.</td>

right before the table closing.

The matter is that this line suppose to be with the same line as the last textbox. This line pushes the comments textbox to the right side of the screen exactly by the length of the text. And I can't figure out how to bring it back so it would be aligned near the text fields.

I want it to look like this:

text|---| comments
text|---| |-------|
text|---| |-------|
text|---| 
text|---| long text here

instead of this:

text|---|                comments
text|---|                |-------|
text|---|                |-------|
text|---|               
text|---| long text here
0

3 Answers 3

1

Does this jsFiddle do what you want?

2 key points:

1. <td rowspan="3" valign="top"> for the td above the text area

2. The last row should be like this

<tr>
  <td>Your Partner name</td>
  <td><input name="Partner" id="Partner" tabindex="5"></td>
  <td colspan="2">This is a text and it suppose to be long. Actually exactly this length.</td>
</tr>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much. I was sitting on it like two hours now. It so obvious when pointed out. Thanks again
1

Couple of things:

- Avoid formatting using nbsp's.
- Use CSS

Like so:

<html>
<head>
<style>

body
{
margin:0;
padding:0;
}
.left
{
float:left;
width:300px;
}
</style>
</head>
<body>
  <div class="left">
    <table cellspacing="20px" border-colour="blue">
        <tr>
            <td>Your&nbsp;Name*</td>
            <td><input name="Name" id="Name" tabindex="1"></td>
            <td valign="top" rowspan="4">
                Comments<br><textarea rows="4" cols="40" name="Comments" tabindex="6"></textarea>
            </td></tr>
        <tr><td>Company</td><td colspan="2"><input name="Company" id="Company" tabindex="2"></td></tr>
        <tr><td>E-mail*</td><td colspan="2"><input name="Email" id="Email" tabindex="3"></td></tr>
        <tr><td>Telephone*</td><td colspan="2"><input name="Phone" id="Phone" tabindex="4"></td></tr>
        <tr>
            <td>Your Partner name</td>
            <td><input name="Partner" id="Partner" tabindex="5"></td>
            <td>This is a text and it suppose to be long. Actually exactly this length.</td>
        </tr>
    </table>
  </div>
</body>
</html>

Comments

0

Try using the colspan instead of having empty <td> tags:

<td colspan="2">long text here</td>

More explanation about colspan here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.