Re: how to Enable/Disable textbox dynamically



kamalesh wrote:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>

JavaScript has only the first letters in common with Java and JavaServer
Pages. If you need a client-side solution, don't post server-side code
here.

[...]
<html>
<SCRIPT LANGUAGE="JavaScript" SRC="include\Calendar.js"></SCRIPT>

Should read

<script type="text/javascript" src="include/calendar.js"></script>

and must not occur as child of the `html' element. Your filenames
should all be lowercase to avoid problems when filename case becomes
important (e.g. after uploading to a server running a Unix system).

<script type="text/javascript" language="javascript">

language="javascript" is redundant.

[...]
function generateReport()
{
document.frmSelectReport.target="_blank";
document.frmSelectReport.submit();

function generateReport(f)
{
f.target = "_blank";
f.submit();

return false;
}

But see below.

}

function enableLoanFields(form, value)
{
if( ( value == "BETWEEN") || ( value == "NOT_BETWEEN") )
{
}
else
{
}
}
</script>

This `script' element must be placed within the `head' or the `body'
element.

<head>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<LINK HREF="include\CB.css" REL="style***" TYPE="text/css"/>
<title>Report Selection</title>

This must be placed before the first `<script ...>' in your code.

</head>

This must be placed after the last `</script>' in your code.

<body>
[...]

The snipped code is entirely irrelevant to your question, and should
have been omitted. Its indenting style is also awfully bad to read.
Use two spaces for each indentation level, not tab characters, at least
when posting code.

[repaired indentation]
<FORM [...] onSubmit="return false;">

<form ... onsubmit="return generateReport(this);">

However, it escapes me why you are relying on client-side scripting this
much. AIUI, it would suffice if you defined target="_blank" in the
first place (instead of setting it in generateReport()) and used
client-side scripting only for form validation.

[...]
<select name="Loan_Amount_Operator"
onchange="javascript:enableLoanFields(this.form, this.value)">

`javascript:' here ranges from being redundant to being a syntax error.
Omit it, and use the following declaration for the default scripting
language once within the `head' element:

<meta http-equiv="Content-Script-Type" content="text/javascript">

That will do no harm, but it may do some good.

<option selected="selected" value="--SELECT--">--SELECT--</option>
<option value="LESS_THAN">&lt;</option>
<option value="LESS_THAN_OR_EQUAL_TO">&lt;=</option>
<option value="EQUAL_TO">=</option>
<option value="EQUAL_TO_OR_GREATER_THAN">=&gt;</option>
<option value="GREATER_THAN">&gt;</option>
<option value="BETWEEN">Between</option>
<option value="NOT_BETWEEN">Not Between</option>
</select>
[...]
<input type="text" name="Min_Loan_Amount">
[...]
<input type="text" name="Max_Loan_Amount" disabled="disabled">
[...]

type="text" is redundant, and names should be lowercase as to ease
scripting the corresponding element objects.

<input type="submit" class="dialogButton" value="Generate Report"
onclick="generateReport()">

This is known to be unreliable. Use the `onsubmit' event handler
attribute of the `form' element instead. See above.

[...]
Now what I want is when user selects loan amount operator as "Between"
or "NOT BETWEEN" then the seconf txt box "MAX_LOAN_AMOUNT" should be
enabled whereas if the user selects the loan amount anything other
that that then the text box "MAX_LOAN_AMOUNT" should be disabled...

I written the function "function enableLoanFields(form, value)" for
the same but don't know how to do this enabling disabling within the
function

Quickhack:

<form ...>
<script type="text/javascript">
function enableLoadFields(o)
{
var e;
if (o && (e = o.form) && (e = e.elements)
&& (e = e["max_loan_amount"]))
{
var dis = !/BETWEEN/i.test(o.value);
if (!(e.disabled = dis)) e.disabled = dis ? "disabled" : "";
}
}
</script>

...
<select ... onchange="enableLoanFields(this)">
...
</select>
...
</form>

As you can see here, your form probably does not need a name (no matter
the position of the `script' element).


HTH

PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
.