473,671 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

validate input without receiving focus

nathj
938 Recognized Expert Contributor
Hi,

I have been looking around the forum and the web for a way to achieve this and so far I have drawn a blank. So I head to the forum as I'm sure someone knows how to do this.

I have a form which I validate as the user enters data, this is straight forward enough. Part of the validation ensures that all mandatory fields are entered before the continue button is enabled.
(unfortunately this is a development site at present and so I can't show it to you). The form uses the onchange event to fire my javascript. Each mandatory item is labelled with red text which changes to black once it has been verified.

However, and here's the tricky part, I am using a third party service on the site that retrieve address information based on UK postcodes. Once an address is selected the relevant fields are populated.

How do I validate these fields so that the user can see they have been approved? I have looked through the event list on W3C and none of them seem to handle this. They most likely candidates require the user to navigate through the fields. If I were completing the form I would want to be able to click the button as soon as the data were entered.

Any idea on how to call the validation of input fields that do not receive the focus?

Example 1 - with onchange, not auto populated
Expand|Select|Wrap|Line Numbers
  1. <input id="title" type="text" maxlength="15" size="47" onchange="validateItem('titlelabel',this.value,'Title:',0,false,5)" title="Title - 15 characters" />
  2.  
Example 2 - Javascript function
Expand|Select|Wrap|Line Numbers
  1. function validateItem(pcID,pcItem,pcDisplay,pnType,plPopulateExtra,pnNumberOfItems)    
  2. {    
  3.  
  4.     var lcRegExp, llIsValid, llUseRegExp
  5.     llIsValid = false 
  6.     llUseRegExp = false
  7.     switch (pnType)
  8.     {
  9.         case 1:    // UK postcode
  10.             pcItem = pcItem.toUpperCase()     
  11.             lcRegExp = '^[A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}|GIR 0AA$' 
  12.             llUseRegExp = true
  13.             break;
  14.         case 2: // email address
  15.             lcRegExp = '^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*$'
  16.             llUseRegExp = true            
  17.             break;
  18.         case 3: // number of set length - basic telephone number check
  19.             lcRegExp = '^[0-9]{6,11}$'                                            
  20.             llUseRegExp = true            
  21.             break;
  22.         case 4: // password validation - alpha numeric characters 6-18 characters long
  23.             lcRegExp = '^[A-Za-z0-9]{6,18}$' 
  24.             llUseRegExp = true            
  25.             break;
  26.     }         
  27.     if (llUseRegExp)
  28.     {
  29.         if (pcItem.match(lcRegExp))
  30.         {    
  31.             llIsValid = true
  32.         }
  33.         else
  34.         {              
  35.             llIsValid = false
  36.         }
  37.     }    
  38.     else
  39.     {                 
  40.         if (pcItem == null||pcItem == ""||pcItem.length < 2)
  41.         {
  42.             llIsValid = false
  43.         }
  44.         else
  45.         {
  46.             llIsValid = true
  47.         }     
  48.     }
  49.  
  50.     if (llIsValid)                                
  51.     {                
  52.         document.getElementById(pcID).innerHTML = pcDisplay
  53.         if (gnValidationCount >= 1)
  54.         {
  55.             gnValidationCount = gnValidationCount - 1
  56.         }
  57.     }
  58.     else
  59.     {    
  60.         document.getElementById(pcID).innerHTML = "<span class='warninglabel'>" + pcDisplay + "</span>"
  61.         if (gnValidationCount <= pnNumberOfItems)
  62.         {
  63.             gnValidationCount = gnValidationCount + 1
  64.         }
  65.     }     
  66.  
  67.     if (gnValidationCount == 0)    
  68.     {
  69.         hideOrShowInput("complete",false)    
  70.     }
  71.     else
  72.     {
  73.         hideOrShowInput("complete",true)    
  74.     }    
  75.     if (plPopulateExtra)
  76.     {
  77.          populateExtra(lcSource, lcDestination, true, true)
  78.     }  
  79. }    
  80.  
note gnValidationCou nt is set at the top of the page as 'global' variable.

Any help on how to call the function without accessing the controls would be greatly appreciated.

Many thanks
nathj
Jun 28 '07 #1
5 2562
acoder
16,027 Recognized Expert Moderator MVP
You could always call a validation function onsubmit.

How are these fields populated? When the value changes, the onchange should fire.
Jun 28 '07 #2
nathj
938 Recognized Expert Contributor
You could always call a validation function onsubmit.

How are these fields populated? When the value changes, the onchange should fire.
Hi there,

I am using the code from Allies Computing - SOAP Web Service Postcode search, and as far as I can tell the following lines make the change:
Expand|Select|Wrap|Line Numbers
  1.     // update the main address form with the correctly formatted, selected address.
  2.     parent.document.contactDetails.organisation.value = jsaddressList[num][0];
  3.     parent.document.contactDetails.address1.value = address[0];
  4.     parent.document.contactDetails.address2.value = address[1];
  5.     parent.document.contactDetails.address3.value = address[2];
  6.     parent.document.contactDetails.address4.value = address[3];
  7.     parent.document.contactDetails.town.value = jsaddressList[num][6];
  8.     parent.document.contactDetails.county.value = jsaddressList[num][7];
  9.     parent.document.contactDetails.postcode.value = jsaddressList[num][8];
  10.  
This is inside a JavaScript function as far as I can tell.

Many thanks
Nathan
Jun 28 '07 #3
nathj
938 Recognized Expert Contributor
Hi,

Further information and a sample test.

This code is a simplistic overview of my problem:


[HTML]<html>

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

function upperCase(x)
{
document.getEle mentById(x).val ue=document.get ElementById(x). value.toUpperCa se()
document.getEle mentById('testl abel').innerHTM L = "Test Label"
}
function populate()
{
document.getEle mentById('fname ').value="testi ng onchange"
}
</script>
</head>

<body>
<input type="button" value="Test" onclick="popula te();">
<p id="testlabel"> Enter your name:</p> <input type="text" id="fname" onblur="upperCa se(this.id)">

</body>
</html>
[/HTML]

If you run this and click the button, you will see the text box populate but not switch to uppercase until focus passes through it. If the onblur is switched to onchange the function to convert to uppercase is not called until you type into the box..

This is a simplistic summary of the problem. I need to be able to call a function on a text box once it has been populated by a separate function. I have tried running the call from the separate function but as I am writing back to a label on a different page it doesn't seem to work.

Does anyone know how to write this so that, in the above example, the label changes as soon as the button is clicked - without adding the code to the button onclick as that is not a possibility in the real live situation?

Many thanks
nathj
Jun 29 '07 #4
gits
5,390 Recognized Expert Moderator Expert
hi ...

what about calling:

Expand|Select|Wrap|Line Numbers
  1. upperCase('fname');
within your populate function?

kind regards ...
Jun 29 '07 #5
nathj
938 Recognized Expert Contributor
The problem has been solved. Many thanks to every one who helped. The code below is the code that was supplied by the third party and it populates the controls I need to validate.
Expand|Select|Wrap|Line Numbers
  1.     // update the main address form with the correctly formatted, selected address.
  2.     parent.document.contactDetails.organisation.value = jsaddressList[num][0];
  3.     parent.document.contactDetails.address1.value = address[0];
  4.     parent.document.contactDetails.address2.value = address[1];
  5.     parent.document.contactDetails.address3.value = address[2];
  6.     parent.document.contactDetails.address4.value = address[3];
  7.     parent.document.contactDetails.town.value = jsaddressList[num][6];
  8.     parent.document.contactDetails.county.value = jsaddressList[num][7];
  9.     parent.document.contactDetails.postcode.value = jsaddressList[num][8];
  10.  
After this code I added the following two lines:

[PHP]
parent.document .contactDetails .address1.oncha nge();
parent.document .contactDetails .postcode.oncha nge();
[/PHP]

Now it all works lovely jubbly. I also think that I did a poor job of explaining my problem but your clear responses helped me to get a better focus on it. Once again this place comes to my rescue.

Cheers
nathj
Jun 29 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2142
by: francisco lopez | last post by:
ok , first of all sorry if my english is not so good, I do my best. here is my problem: I don´t know much javascript so I wrote a very simple one to validate a form I have on my webpage. could you please have a look at the following script: ------------------------------------------------------------
2
1882
by: Meredith | last post by:
I am using a script to validate a form using the presence of a value in one field and determine if there is a value in one of two fields. It is an either/or situation. If the date rcvd field is not "", then either the ref names has to be filled in OR the res date has to be filled in. I have tried many combinations of this. Any suggestions will be greatly appreciated. <script language="JavaScript"> function ValidateForm(){
2
1684
by: Jure Erznoznik | last post by:
I made a table that shows 20 rows of a table at a time. When the user presses down or up arrow, the table will scroll as necessary filling new rows. But I have a problem with the following code snippet: while (tr.sectionRowIndex < this.scrollRowsVisible && this._DBCacheS > 0) { //Scroll Up // this.tBody.removeChild(this._DBRowCache.element); this.tBody.deleteRow(-1);
2
3478
by: NishSF | last post by:
Would anyone have any suggestions/javascript code so that if one clicks the Radio Button "Yes" below he has the option of selecting any of the six CheckBox below. If the user clicks on Radio Button "No", he should not have the option of clicking on any of the six checkboxes. See Code attached. Thank you so much in advance for your help as I can't get to make this combo work. <p>Did you have any problems finding any of the information...
2
3621
by: Basr | last post by:
I tried to use this script to validate the input of the form Ford. When I use the Input ype Button the script is OK I want to use a picture as a button but then the script does not function. Can someone help me a little. Thanks in advance Marcel
1
3815
by: huhuhuhu | last post by:
i am trying to validate radiobutton n checkbox but to no avail. this is the code that i m using to validate radiobutton>> <script language="JavaScript"> function checkForm() { var cgender with(window.document.msgform) {
3
2469
by: shyamg | last post by:
hi all, This javascript is working IE but not working in FIreFox, validating text fields. var dealerid = new keybEdit('abcdefghijklmnopqurstuvwxyz01234567890 ','Alpha-numeric input only.'); var dealinit = new keybEdit('abcdefghijklmnopqurstuvwxyz01234567890 ','Alpha-numeric input only.'); var dealername = new keybEdit('abcdefghijklmnopqurstuvwxyz ','Alphabets input only.'); var rank = new...
3
8412
by: =?Utf-8?B?cHJvZ2dlcg==?= | last post by:
I have a C# application that hosts an AxWebBrowser control which I automate by sending mouse clicks and keyboard input. I have had various problems in doing this due to a bug in the AxWebBrowser receiving input when it is hosting a flash page however I have got it to work using SendKeys for the keyboard input and the Windows API SendInput function for the mouse clicks (along with Cursor.Position) however I'd like to do this in the...
10
2786
mariodavi
by: mariodavi | last post by:
Hi everybody, how to validate input text in the follow: if option combo = 1,2 e 3, input 1 and input 2 must be filled, if one of this values not selected in combo (to be others), filled input 3. validate code with error below: funcion validate () { ...
0
8820
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8598
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8670
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7433
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6223
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4224
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1809
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.