473,385 Members | 1,523 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,385 software developers and data experts.

Script crashing IE

When I run the following script it displays a form with a dropdown list
and four text boxes. If I select "No" from the dropdown list all the
text boxes are disabled. If I select "Yes" from the dropdown list
Internet Explorer 6 stops responding.

What I want it to do is:
- Disable all the text boxes if "No" is selected,
- Determine which text field has the focus and then select the text that
is inside the text field if "Yes" is selected

Why is it crashing IE?

<html>
<head>
<script language="JavaScript">
function IsFieldActive(fld) {
if ((document.frmFormName.OptionsList.value == "No")) {
DisableFields(fld);
}
else {
SelectFields(fld)
}
}

function DisableFields(fld) {
this.frmFormName.field1.blur(fld)
this.frmFormName.field2.blur(fld)
this.frmFormName.field3.blur(fld)
this.frmFormName.field4.blur(fld)
}

function SelectFields(fld) {
this.frmFormName.field1.focus(fld)
this.frmFormName.field1.select(fld)

this.frmFormName.field2.select(fld)
this.frmFormName.field2.select(fld)

this.frmFormName.field3.select(fld)
this.frmFormName.field3.select(fld)

this.frmFormName.field4.select(fld)
this.frmFormName.field4.select(fld)
}
</script>
</head>
<body>
<form name="frmFormName">
<table border="1" align="center">
<tr>
<td>Make Fields Active</td>
<td colspan="4">
<select name="OptionsList" size="1">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</td>
</tr>
<tr>
<td>Field 1:</td>
<td><input type="text" name="field1" value="1"
onFocus="IsFieldActive(this.form.field1.value)"></td>
<td>Field 2:</td>
<td><input type="text" name="field2" value="2"
onFocus="IsFieldActive(this.form.field2.value);"></td>
</tr>
<tr>
<td>Field 3:</td>
<td><input type="text" name="field3" value="3"
onFocus="IsFieldActive(this.form.field3.value);"></td>
<td>Field 4:</td>
<td><input type="text" name="field4" value="4"
onFocus="IsFieldActive(this.form.field4.value);"></td>
</tr>
</table>
</form>
</body>
</html>
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #1
1 1347
Luis wrote:
When I run the following script it displays a form with a dropdown list
and four text boxes. If I select "No" from the dropdown list all the
text boxes are disabled. If I select "Yes" from the dropdown list
Internet Explorer 6 stops responding.

What I want it to do is:
- Disable all the text boxes if "No" is selected,
- Determine which text field has the focus and then select the text that
is inside the text field if "Yes" is selected

Why is it crashing IE?


Because you are calling the select() method on a form control after focus
has been set to that control. Calling select() sets focus to the control,
which triggers the onfocus event, which calls select() which sets focus,
which triggers the onfocus event, which calls select() etc etc.

As well, there are number of other errors, such as select() and blur() don't
take arguments, and you can't select() more than a single input - or rather,
calling select() on subsequent controls moves the focus and selects only
that control's value.

Given your requirements:
What I want it to do is:
- Disable all the text boxes if "No" is selected,
- Determine which text field has the focus and then select the text that is
inside the text field if "Yes" is selected

The solution is easy:

<script type="text/javascript">
function IsFieldActive(inp) {
var sel;
if (inp.form &&
(sel = inp.form.elements['OptionsList'])) {

if (sel.options[sel.selectedIndex].value == 'Yes') {
// Yes is selected, select
// the value of this input
inp.select();
} else {
// the only input you need to blur()
// is the one that just got focus
inp.blur();
}
}
}
</script>

and each of your inputs should read:

<input type="text" name="field1" onfocus="IsFieldActive(this);">

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #2

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

Similar topics

4
by: Lee Marsh | last post by:
Okay, I posted this over at alt.php, but got nil response, so I'm posting it hear again in hopes of getting a response. Sorry to anyone reading this twice: Okay...so on my website, where people...
1
by: Newbie | last post by:
Please Help, I have 2 <div's> named "DETdetails" & "MEMOdetails" in my ASP page that loads an external css file for these 2 <div's> I want both <div's> to be static when the page scrolls...
2
by: codesmithsf | last post by:
I'm using PHP 4.2.2 and Apache 2.0.4.0. A script running on a virtual host had an endless loop in it that brought Apache to its knees. I have max_execution_time=90 and memory_limit=32M to...
14
by: Java and Swing | last post by:
static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { // this will store the result in a Python object PyObject *finalResult; // get arguments from Python char *result = 0; char *in=...
1
by: mydejamail | last post by:
My PHP setup is not updating the error_log, I have checked all the error logging related settings and they have all been set. The script is also crashing inexplicably. Whenever I call a specific...
2
by: yangsuli | last post by:
It works perfectly well before but today my browser cannot get this php script i tried to run it in the localhost and it reported a seg fault :( i donot konw what to do.....:( restarting the...
1
by: dragze | last post by:
Hi, On one of the pages of my site i use two javascripts, one makes transparency of png's work in IE, and the other embeds a flash player. Now use one of the scripts it works fine, use both and...
2
by: =?Utf-8?B?QW5uZXh4eHh4eHg=?= | last post by:
My computer keeps crashing. The files created when it does this are: WERdc15.dir00\Mini090708-03.dmp WERdc15.dir00\sysdata.xml has anybody any idea of what these files are and the solution to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.