473,395 Members | 2,253 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Problem with JavaScript in IE

mc
I've written some Javascript to resize a text box once the text gets too
long to fit, however running the function (in IE7) has a rather odd side
effect.

If you open the page and type in a text string (one line of text) longer
than 43 (ish) characters it reshapes the surrounding table, ignoring the
explicit column width set on the first column.

It's best viewed in a browser, but for those that would rather not I'll
try and explain what is happening.

If you enter text that causes the function to set the value of
textBox.Rows and a Row contains a string longer than the width of the
first Column it ignores the Column widths set on the surrounding table
and sets it's own value.

Any ideas how I can adjust the JS to stop the Table getting reshaped?

Works fine in Firefox, I'm guessing it's another IE7 "Feature".

TIA
MC
----Entire Page Below this line----

<html>
<body>
<form>

<script type="text/javascript">
<!--
function ResizeTextBox(textBox,minRows) {
rowWidthInChars = parseInt(textBox.offsetWidth / 8)-2;
textBoxLines = textBox.value.split('\n');
newRowCount = 1;
for (x=0;x < textBoxLines.length; x++) {
if(textBoxLines[x].length >= rowWidthInChars) {
newRowCount += Math.floor(textBoxLines[x].length/rowWidthInChars);
}
}
newRowCount += textBoxLines.length;
textBox.rows = newRowCount;
if (textBox.rows < minRows) {
textBox.rows = minRows
}
}
// -->
</script>

<table border="2" style="width:100%;">
<tr>
<td class="question" colspan="2">Text:</td>
</tr>
<tr>
<td class="answer" colspan="2">
<textarea rows="4" cols="20" id="tbOne"
onkeyup="ResizeTextBox(this,4)" style="width:98%;"></textarea>
</td>
</tr><tr>
<td style="width:300px;">Check Box:</td>
<td>
<select>
<option value="X">X</option>

</select></td>
</table>
</form>
</body>
</html>
Mar 11 '07 #1
2 1535

mc wrote:
Any ideas how I can adjust the JS to stop the Table getting reshaped?
Adjust the html instead of the javascript. Remove all colspans, place
the last row in the separate table.

<table border="2" style="width:100%;">
<tr>
<td class="question">Text:</td>
</tr>
<tr>
<td class="answer">
<textarea rows="4" cols="20" id="tbOne"
onkeyup="ResizeTextBox(this,4)" style="width:98%;"></textarea>
</td>
</tr>
<tr>
<td>
<table width="100%">
<tr>
<td style="width:300px;">Check Box:</td>
<td><select><option value="X">X</option></select></
td>
</tr>
</table>
</td>
</tr>
</table>

Mar 12 '07 #2
mc
Ok, Thats one potential solution, however, The "real" table is
considerably larger than the one presented in my demo example. As I
would like to use the TextBox and associated JS anywhere without making
specific design discisions I was hoping to get a JS answer.

My gut instinct tells me it's another IE problem and there is no simple
answer and that something like the solution you present is the only answer.

Thanks
MC
marss wrote:
mc wrote:

>>Any ideas how I can adjust the JS to stop the Table getting reshaped?


Adjust the html instead of the javascript. Remove all colspans, place
the last row in the separate table.

<table border="2" style="width:100%;">
<tr>
<td class="question">Text:</td>
</tr>
<tr>
<td class="answer">
<textarea rows="4" cols="20" id="tbOne"
onkeyup="ResizeTextBox(this,4)" style="width:98%;"></textarea>
</td>
</tr>
<tr>
<td>
<table width="100%">
<tr>
<td style="width:300px;">Check Box:</td>
<td><select><option value="X">X</option></select></
td>
</tr>
</table>
</td>
</tr>
</table>
Mar 12 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Aaron Prohaska | last post by:
I have just run into a problem where I have a page that posts back to itself to execute code, except when the page does the post back it somehow executes code that is in our home page for the site....
4
by: Federico Bari | last post by:
Good morning all from italy, i have probably a compatibility problem with a html/javascript page. The aim of the code of the file test.htm you find here following (copy the 3 files in the...
1
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function...
4
by: JesusFreak | last post by:
From: us_traveller@yahoo.com (JesusFreak) Newsgroups: microsoft.public.scripting.jscript Subject: toolbar script problem NNTP-Posting-Host: 192.92.126.136 Recently, I downloaded the following...
1
by: Julius Mong | last post by:
Dear all, according to the ASV3 manual known problem section, to make an <a> execute some Javascript onclick: ...
12
by: Jeff S | last post by:
In a VB.NET code behind module, I build a string for a link that points to a JavaScript function. The two lines of code below show what is relevant. PopupLink = "javascript:PopUpWindow(" &...
0
by: Thomas Due | last post by:
Hello, I am in the process of making my asp.net form to validate as xhtml 1.0 strict. So far I am doing well, but now I have a problem. The problem concerns specifically DropDownList and...
1
by: mostafahamdyfcis | last post by:
Hello all I have used the sample code which exist in the following URL: http://www.eggheadcafe.com/articles/javascript_modal_dialog.asp which create modal dialog box, but some problem...
4
by: r_ahimsa_m | last post by:
Hello, I am learning WWW technologies in Linux. I created index.html file which I can browse with Firefox/Konqueror using URL localhost/~robert/rozgloszenia/index.html. The page looks fine but...
1
by: paulyXvpf | last post by:
Hello javascript folks, PROBLEM: Javascript dropdown problem in IE 6 and IE7 DESCRIPTION: menu falls behind a container box on web page COMMENTS: It works fine in Firefox but not in IE 6/7...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.