It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

New in Javascript. Please Help....

New in Javascript. Please Help....

Postby Santanu on Tue Jan 20, 2009 6:02 pm

I have two text fields. One for 9450 device and another for QR device. Now if the user enters a Transmitter id which is already assigned into the text field for 9450 device and hits SAVE button, no error message displays in the screen. Same for the QR text field.
Now we have to modify the code so that we can display an alert message when the user enters a TXID which is already assigned and in the range into the text field for 9450 device and hits the SAVE button.

I tried to modified the code in following way (please see the BOLD PART)

I have added the methods isAssigned9450Tag() for 9450 device and isAssignedQRTag() for QR device. Both of these methods returns true when the TXID is already assigned, false otherwise.

for ( int i = 0; i < testTxs.length; ++i )
{
if ( true == DeviceIDRange.t9450.equals( testTxs[i].type ) )
{
testTx9450Value = testTxs[i].txId;
boolean isdup9450tag = dup9450tag.isAssigned9450Tag( testTx9450Value );
System.out.println("The value of isdup9450tag is: " + isdup9450tag + "\n\n");
}
else
if ( true == DeviceIDRange.tinov.equals( testTxs[i].type ) )
{
testTxInovValue = testTxs[i].txId;
boolean isdupQRtag = dup9450tag.isAssignedQRTag( testTxInovValue );
System.out.println("The value of isdupQRtag is: " + isdupQRtag + "\n\n");
}
}


I have tried to implement them into the javascript function for Save button like the following:

function testTxCheck( element )
{
if ( 0 != element.value.length )
{
if ( true == isNumeric( element.value ) )
{
if ( false == testTxCheckNumberType( element.value, element.name.substring(6) ) )
{
alert( element.value + " must be within a specified TX ID Range" );
element.value = "";
element.focus();
return false;
}

else
{
if ( true == isdup9450tag )
{
alert("The TXID is already assigned");
return false;
}
else if ( true == isdupQRtag )
{
alert("The TXID is already assigned");
return false;
}
}
}
else
{
alert( element.value + " is not a numeric value" );
element.value = "";
element.focus();
return false;
}
}
return true;
}

But I am not successful. I am wondering if someone can help me out to display the alert message when the user enters a TXID which is already assigned into the text fields both for 9450 or QR devices and hits the save button. I would appreciate your kind help. Thanks..
Santanu
 
Posts: 16
Joined: Sat Aug 09, 2008 5:20 pm

Re: New in Javascript. Please Help....

Postby Santanu on Tue Jan 20, 2009 6:28 pm

Please find the java script part for this file:
function handleSave()
{
if ( true == validateValues( document.formSettings ) )
{
disable( document.formSettings.btnSave );
document.formSettings.wardenAction.value = "update.deviceid.range.settings";
document.formSettings.submit();
}
}

function handleClose()
{
document.formSettings.wardenAction.value = "close.global.settings";
document.formSettings.submit();
}

function handleMissing( id, minVal, maxVal, type )
{
document.formSettings.wardenAction.value = "view.lost.tx.settings";
document.formSettings.missingRangeID.value = id;
document.formSettings.missingTagMin.value = minVal;
document.formSettings.missingTagMax.value = maxVal;
document.formSettings.missingTagType.value = type;
document.formSettings.submit();
}

function testTxCheckNumberType( number, type )
{
var iNumber = parseInt( number );
for ( var i = 0; i < document.formSettings.elements.length; i++ )
{
if ( document.formSettings.elements[i].type == 'select-one' )
{ // The two fields before this are entry fields for min/max TX IDs.
// Check that those fit within the range for the type selected
// Check that min < max
tempMin = document.formSettings.elements[i-2].value;
tempMax = document.formSettings.elements[i-1].value;
tempType = document.formSettings.elements[i].value;
if ( tempMin != '' && tempMax != '' && tempType != '' )
{
if ( type == tempType
&& parseInt( tempMin ) <= iNumber
&& iNumber <= parseInt( tempMax ) )
return true;
}
}
}
return false;
}

function inovCheck( element )
{
if ( 0 != element.value.length )
{
if ( true == isNumeric( element.value ) )
{
if ( true == testTxCheckNumberType( element.value, '<%=DeviceIDRange.tinov%>' ) )
{
return true;
}
}
}
return false;
}

function testTxCheck( element )
{
if ( 0 != element.value.length )
{
if ( true == isNumeric( element.value ) )
{
if ( false == testTxCheckNumberType( element.value, element.name.substring(6) ) )
{
alert( element.value + " must be within a specified TX ID Range" );
element.value = "";
element.focus();
return false;
}

else
{
if ( true == isdup9450tag )
{
alert("The TXID is already assigned");
return false;
}
else if ( true == isdupQRtag )
{
alert("The TXID is already assigned");
return false;
}
}
}
else
{
alert( element.value + " is not a numeric value" );
element.value = "";
element.focus();
return false;
}
}
return true;
}

function testTxTypeChange( element )
{
if ( 0 != element.value.length )
{
if ( element.value == "<%=DeviceIDRange.t9450%>" )
{
enable( document.formSettings.testTx<%=DeviceIDRange.t9450%> );
}
else
if ( element.value == "<%=DeviceIDRange.tinov%>" )
{
enable( document.formSettings.testTx<%=DeviceIDRange.tinov%> );
}
}
}

function validateValues( what )
{
var valid = true;
for ( var i = 0; i < what.elements.length && true == valid; i++ )
{
myType = what.elements[i].type;
myName = what.elements[i].name;

if ( myType == 'text' )
{
if ( false == (valid = validateFieldEntry( what.elements[i].value )) )
alert( 'Please do not enter non-numeric transmitter IDs.' );
}
else
if ( myType == 'select-one' )
{ // The two fields before this are entry fields for min/max TX IDs.
// Check that those fit within the range for the type selected
// Check that min < max
tempMin = what.elements[i-2].value;
tempMax = what.elements[i-1].value;
tempType = what.elements[i].value;
if (tempType != '' && tempMin != '' && tempMax != '')
{
if ( '9450' == tempType && false == (valid = (true == in9450Range( tempMin ) && true == in9450Range( tempMax ))) )
{
alert( 'Please place all 9450 transmitter IDs in the range of 1 - 240 and 513 - 1023' );
}
else
if ( 'mom' == tempType && false == (valid = (true == (1 <= tempMin && tempMin <= tempMax && tempMin <= tempMax && tempMax <= 240))) )
{
alert( 'Please place all Mother transmitter IDs in the range of 1 - 240' );
}
else
if ( 'inov' == tempType && false == (valid = (true == inQRRange( tempMin ) && true == inQRRange( tempMax ))) )
{
alert( 'Please place all QR IDs in the range 1-65535' );
}
else
if ( false == (valid = validateMinMax( tempMin, tempMax )) )
{
alert( 'Please ensure that minimum transmitter IDs are lower than maximum transmitter IDs.' );
}
}
else
{
valid = (tempType == '' && tempMin == '' && tempMax == '');
if ( false == valid )
{
alert( 'Please ensure a Min, Max, and Type are configured.' );
}
}
}
}

if ( true == valid )
{
if ( true == (valid = testTxCheck( document.formSettings.testTx<%=DeviceIDRange.t9450%> )) )
{
if ( true == (valid = testTxCheck( document.formSettings.testTx<%=DeviceIDRange.tinov%> )) )
{
if ( 0 != document.formSettings.inovMinNew.value.length
&& 0 != document.formSettings.inovMaxNew.value.length )
{
if ( true == (valid = (true == validateMinMax( document.formSettings.inovMinNew.value, document.formSettings.inovMaxNew.value )
&& 1 <= parseInt( document.formSettings.inovMinNew.value )
&& 65280 >= parseInt( document.formSettings.inovMaxNew.value ))) )
{
if ( true == (valid = inovCheck( document.formSettings.inovMinNew )) )
{
if ( false == (valid = inovCheck( document.formSettings.inovMaxNew )) )
{
alert( 'Please ensure that maximum transmitter ID are lower than or equal to maximum transmitter IDs.' );
}
}
else
alert( 'Please ensure that mimimum transmitter ID are higher than or equal to mimimum transmitter IDs.' );
}
else
alert( 'Please place all repeater/locator IDs in the range 1-65280 and minimum <= maximum' );
}
}
}
}

return valid;
}

function in9450Range(val)
{
var iNum = parseInt( val );
return ( (1 <= iNum && iNum <= 240) || (257 <= iNum && iNum <= 1023));
}

function inQRRange( val )
{
var iNum = parseInt( val );
return 1 <= iNum && iNum <= 65535;
}

function validateMinMax( minVal, maxVal )
{
return parseInt( minVal ) <= parseInt( maxVal );
}

function validateFieldEntry( entry )
{
return true == isNumeric( entry ) || '' == entry;
}

function handleMarkDelete( entry )
{
if ( 'false' == entry.value )
entry.checked = entry.value = confirm( 'Are you sure you want to delete this range?' );
entry.value = entry.checked;
}

function do_onLoad()
{
<% if ( true == is9450 ) {
if ( true == testTx9450 ) { %>
enable( document.formSettings.testTx<%=DeviceIDRange.t9450%> );
<% } else { %>
disable( document.formSettings.testTx<%=DeviceIDRange.t9450%> );
<% }
} %>
<% if ( true == isInov ) {
if ( true == testTxInov ) { %>
enable( document.formSettings.testTx<%=DeviceIDRange.tinov%> );
<% } else { %>
disable( document.formSettings.testTx<%=DeviceIDRange.tinov%> );
<% }
} %>
}

</script>
Santanu
 
Posts: 16
Joined: Sat Aug 09, 2008 5:20 pm

Re: New in Javascript. Please Help....

Postby Santanu on Tue Jan 20, 2009 6:36 pm

please find the other related par below:

<%
GlobalSettings theSettings = GlobalSettingsHandler.cacheRetrieve( session );
DeviceIDRange[] deviceIDRange = theSettings.getDeviceIDRange();
XMLLicenseBean licenseBean = new XMLLicenseBean();
XMLTagBean dup9450tag = new XMLTagBean();
boolean is9450 = licenseBean.retrieveLicense( XMLLicenseBean.f9450 );
boolean isInov = licenseBean.retrieveLicense( XMLLicenseBean.fInov );
boolean testTx9450 = 0 != theSettings.get9450DeviceIDRange().length;
boolean testTxInov = 0 != theSettings.getQRDeviceIDRange().length;

String testTx9450Value = "";
String testTxInovValue = "";

GlobalSettings.TestTx[] testTxs = theSettings.getTestTxs();
for ( int i = 0; i < testTxs.length; ++i )
{
if ( true == DeviceIDRange.t9450.equals( testTxs[i].type ) )
{
testTx9450Value = testTxs[i].txId;
boolean isdup9450tag = dup9450tag.isAssigned9450Tag( testTx9450Value );
System.out.println("The value of isdup9450tag is: " + isdup9450tag + "\n\n");
}
else
if ( true == DeviceIDRange.tinov.equals( testTxs[i].type ) )
{
testTxInovValue = testTxs[i].txId;
boolean isdupQRtag = dup9450tag.isAssignedQRTag( testTxInovValue );
System.out.println("The value of isdupQRtag is: " + isdupQRtag + "\n\n");
}
}
%>


*************************************


<% if (( true == is9450 ) || ( true == isInov )) { %>
<tr>
<td align="center" class="input-style-4">Test TX ID #</td>
<td align="center" class="input-style-4">Type</td>
</tr>
<% } else { %>
<tr>
<td align="center" class="input-style-4"></td>
<td align="center" class="input-style-4"></td>
</tr>
<% } %>

<% if ( true == is9450 ) { %>
<tr>
<td width="100px" align="center" class="input-style-4">
<input type="text" name="<%="testTx"+DeviceIDRange.t9450%>" class="input-style-3" value="<%=testTx9450Value%>" size="5" maxlength="5" onChange="testTxCheck( this );">
</td>
<td class="input-style-4">9450</td>
</tr>
<% } else { %>
<input type="hidden" name="<%="testTx"+DeviceIDRange.t9450%>" value="">
<% } %>
<% if ( true == isInov ) { %>
<tr>
<td width="100px" align="center" class="input-style-4">
<input type="text" name="<%="testTx"+DeviceIDRange.tinov%>" class="input-style-3" value="<%=testTxInovValue%>" size="5" maxlength="5" onChange="testTxCheck( this );">
</td>
<td class="input-style-4">QR</td>
</tr>
<% } else { %>
<input type="hidden" name="<%="testTx"+DeviceIDRange.tinov%>" value="">
<% } %>
</table>
</td>
</tr>

<% if ( true == isInov ) { %>
<tr><td><hr></td></tr>
<tr>
<td align="center" class="input-style-4">Extend Repeater/Locator Ranges</td>
</tr>

<!-- Row for data entry -->
<tr>
<td align="center" height="18px">
<table width="420px" height="18" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="100px" class="input-style-3">Min </td>
<td width="100px" class="input-style-3">Max </td>
<td width="90px" class="input-style-3">Type </td>
<td width="100px" class="input-style-3">Delete</td>
</tr>
</table>
</td>
</tr>

<tr height="1px">
<td align="center">
<!-- div class="scroll" -->
<table id="tagTable" width="420px" border="0" cellspacing="0" cellpadding="0">
<% for ( int x = 0; x < theSettings.getInovExtRange().length; x++ )
{
GlobalSettings.InovExtRange ier = theSettings.getInovExtRange()[x];
String idFieldName = "inov.id." + x;
String minFieldName = "inov.min." + x;
String maxFieldName = "inov.max." + x;
String deletedFieldName = "inov.del." + x;
%>
<tr>
<input name="<%=idFieldName%>" type="hidden" value="<%=ier.getID()%>">

<td width="100px" class="input-style-4">
<div align="center">
<input disabled name="<%=minFieldName%>" type="text" class="input-style-3" value="<%=ier.getMin()%>" size="5" maxlength="5">
</div>
</td>

<td width="100px" class="input-style-4">
<div align="center">
<input disabled nname="<%=maxFieldName%>" type="text" class="input-style-3" value="<%=ier.getMax()%>" size="5" maxlength="5">
</div>
</td>

<td width="90px" class="input-style-4"><%=(ier.getType().equals(Device.RPR) ? "Repeater" : "Locator" )%></td>

<td width="100px" class="input-style-4">
<div align="center">
<% if ( 0 != deletedFieldName.length() ) { %>
<input type="checkbox" name="<%=deletedFieldName%>" value="true">
<% }
else
{ %>
&nbsp;
<% } %>
</div>
</td>
</tr>
<% } // for ( int x = 0; x < theSettings.getInovExtRange().length; x++ ) %>
<tr>
<td width="100px" class="input-style-4">&nbsp;<div align="center"><input name="inovMinNew" type="text" class="input-style-3" value="" size="5" maxlength="5"></div></td>
<td width="100px" class="input-style-4">&nbsp;<div align="center"><input name="inovMaxNew" type="text" class="input-style-3" value="" size="5" maxlength="5"></div></td>
<td width="90px" class="input-style-4">&nbsp;<div align="center">
<select name="inovTypeNew">
<option value="" >Select </option>
<option value="<%=Device.RPR%>" >Repeater</option>
<option value="<%=Device.LOC%>" >Locator </option>
</select>
</div></td>
<td width="100px">&nbsp;</td>
</tr>
</table>
<!-- /div -->
</td>
</tr>
<% } else { %>
<input type="hidden" name="inovMinNew" value="">
<input type="hidden" name="inovMaxNew" value="">
<% } %>
<!-- ends row for data entry -->
<tr><td><hr></td></tr>

<!-- Row for buttons -->
<tr>
<td align="center">
<table width="50%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="30%" align="center"><input name="btnSave" type="button" id="btnSave" onClick="handleSave();" value="Save"> </td>
<td width="30%" align="center"><input name="btnCancel" type="button" id="btnCancel" onClick="handleClose();" value="Close"></td>
</tr>
</table>
</td>
</tr><!-- ends row for buttons -->
Santanu
 
Posts: 16
Joined: Sat Aug 09, 2008 5:20 pm


Who is online

Users browsing this forum: No registered users and 5 guests