Forum Moderators: open
Note: most of the identifying information has been removed from the pages, but their behavior in a browser matches the original, unedited, versions.
Sample 1
*************************************
<html>
<head>
<title>
VS functions don't work on this page
</title>
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script>
function changefunc ()
{
alert('in changefunc');
}
function dummyfunc ()
{
alert('in dummyfunc');
return false;
}
function chcount (theform)
{
alert('in chcount');
curcount = theform.curCount.value;
newcount = theform.repeatCount.value;
if (curcount!= newcount)
{
// The new value must be a non-negative integer.
try
{
if newcount < 0
{
alert("The repeat count must be a non-negative integer.");
theform.reset();
return false;
}
}
catch (err)
{
// The value couldn't be used as a number.
alert(err + "The repeat count must be a non-negative integer.");
theform.reset();
return false;
}
}
else
{
// The count hasn't changed; don't send.
return false;
}
// If we got here, we have a good new repeat count; send it.
return true;
}
</script>
</head>
<body>
<h1 align="left">
<b>
<font face="Arial" color="#000080" size="6">
VS functions don't work on this page
</font>
</b>
</h1>
<hr />
<table border=0>
<form method=POST action="sample1.html" name="sample1">
<tr valign=top>
<td align=left>
Input 1
</td>
<td align=center>
<input type="text" onchange="changefunc()" name="repeatCount" size="6" maxlength="256" value="1" />
</td>
<td align=center>
<input type=hidden name=curCount value="1">
<input type=submit name="useraction" value="Change Count" onclick="return chcount(this.form);">
</td>
</tr>
</form>
<form method=POST action="sample1.html" name="sample1">
<tr valign=top>
<td align=left>
</td>
<td align=center>
</td>
<td align=center>
<input type=submit name="useraction" value="Dummy button" onclick="return dummyfunc();">
</td>
</tr>
</form>
</table>
</body>
</html>
*************************************
Sample 2
*************************************
<html>
<head>
<title>
VS functions work on this page
</title>
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script>
function changefunc (theform)
{
alert('in changefunc');
}
function chtype (theform)
{
alert('in chtype');
curtype = theform.curType.value;
for (var i = 0; i < theform.imagerType.length; i++)
{
if (theform.imagerType[i].checked &&
theform.imagerType[i].defaultChecked)
{
// The imager type hasn't changed; don't send the data
return false;
}
}
// The imager type has been changed; confirm the change
if (confirm("Changing this data has no effect, since \n" +
"this is a dummy page.\n" +
"Proceed?"))
{
return true;
}
theform.reset();
return false;
}
function chmode (theform)
{
alert('in chmode');
curmode = theform.curMode.value;
optnum = theform.imagerMode.selectedIndex;
newmode = theform.imagerMode.options[optnum].value;
if (curmode!= newmode)
{
return true;
}
else
{
return false;
}
}
</script>
</head>
<body>
<h1 align="left">
<b>
<font face="Arial" color="#000080" size="6">
VS functions work on this page
</font>
</b>
</h1>
<table border=0>
<form method=POST action="sample2.html" name="sample2">
<tr valign=top>
<td align=left>
input 1
</td>
<td align=center>
<input type=radio onchange="changefunc()" name=imagerType value="1" checked='checked'>type1<input type=radio onchange="changefunc()" name=imagerType value="2">type2
</td>
<td align=center>
<input type=hidden name=curType value="1">
<input type=submit name="useraction" value="Change Type" onclick="return chtype(this.form);">
</td>
</tr>
<tr valign=top>
<td align=left>
input 2
</td>
<td align=center>
<select name="imagerMode" onchange="changefunc()">
<option value='1'>Option 1</option><option value='2'>Option 2</option><option value='3' selected='selected'>Option 3</option>
</select>
</td>
<td align=center>
<input type=hidden name=curMode value="3">
<input type=submit name="useraction" value="Change Mode" onclick="return chmode(this.form);">
</td>
</tr>
</form>
</table>
</body>
</html>
*************************************
Thanks in advance for any help you can offer.
Barry Carroll
[edited by: jatar_k at 1:13 am (utc) on May 20, 2006]
[edit reason] no sigs thanks [/edit]
Text.onchange
the handler invoked when input value changes---------------------------------------------------------
Availability
JavaScript 1.0Synopsis
<input type="text" onchange="handler" ... >
text.onchangeDescription
The onchange property of a Text element refers to an event handler function that is invoked when the user changes the value in the input field and then "commits" those changes by moving keyboard focus (i.e., by clicking the mouse elsewhere or pressing Tab or Return).
Is this wrong?
Barry
You do have a syntax error in the script on the first page:
if newcount < 0. If-conditions always need to be enclosed by ( and ).
if (newcount < 0)