Page 2 of 2

Re: Validating user input before save

Posted: Fri Oct 05, 2012 9:00 pm
by parkerjnc
So here is what I ended up with. I added an HTML object to my form below the Package ID field which just contains

Code: Select all

<span id="pkgIdCheck> </span>
In the Form's Custom Code section for Javascript I added the following function:

Code: Select all

function showHint(str)
{
var xmlhttp;
if (str.length==0)
  { 
  document.getElementById("pkgIdCheck").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("pkgIdCheck").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","/db/tcms/checkPackageID.php?q="+str,true);
xmlhttp.send();
}
In the On Blur event of the Package ID field I make a call to this showHint function passing in the value of the Package ID field.

This allows the user to be warned if they re-use a package ID.

Re: Validating user input before save

Posted: Tue Oct 09, 2012 5:00 am
by admin
OK, that works.

Steven