Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

Validating user input before save

parkerjnc
Posts: 15
Joined: Wed Sep 05, 2012 5:15 am

Re: Validating user input before save

Unread post 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.
Attachments
Package ID check message
Package ID check message
check.png (8.2 KiB) Viewed 1785 times
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: Validating user input before save

Unread post by admin »

OK, that works.

Steven
Post Reply