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 -
<input id="title" type="text" maxlength="15" size="47" onchange="validateItem('titlelabel',this.value,'Title:',0,false,5)" title="Title - 15 characters" />
-
Example 2 - Javascript function -
function validateItem(pcID,pcItem,pcDisplay,pnType,plPopulateExtra,pnNumberOfItems)
-
{
-
-
var lcRegExp, llIsValid, llUseRegExp
-
llIsValid = false
-
llUseRegExp = false
-
switch (pnType)
-
{
-
case 1: // UK postcode
-
pcItem = pcItem.toUpperCase()
-
lcRegExp = '^[A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}|GIR 0AA$'
-
llUseRegExp = true
-
break;
-
case 2: // email address
-
lcRegExp = '^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*$'
-
llUseRegExp = true
-
break;
-
case 3: // number of set length - basic telephone number check
-
lcRegExp = '^[0-9]{6,11}$'
-
llUseRegExp = true
-
break;
-
case 4: // password validation - alpha numeric characters 6-18 characters long
-
lcRegExp = '^[A-Za-z0-9]{6,18}$'
-
llUseRegExp = true
-
break;
-
}
-
if (llUseRegExp)
-
{
-
if (pcItem.match(lcRegExp))
-
{
-
llIsValid = true
-
}
-
else
-
{
-
llIsValid = false
-
}
-
}
-
else
-
{
-
if (pcItem == null||pcItem == ""||pcItem.length < 2)
-
{
-
llIsValid = false
-
}
-
else
-
{
-
llIsValid = true
-
}
-
}
-
-
if (llIsValid)
-
{
-
document.getElementById(pcID).innerHTML = pcDisplay
-
if (gnValidationCount >= 1)
-
{
-
gnValidationCount = gnValidationCount - 1
-
}
-
}
-
else
-
{
-
document.getElementById(pcID).innerHTML = "<span class='warninglabel'>" + pcDisplay + "</span>"
-
if (gnValidationCount <= pnNumberOfItems)
-
{
-
gnValidationCount = gnValidationCount + 1
-
}
-
}
-
-
if (gnValidationCount == 0)
-
{
-
hideOrShowInput("complete",false)
-
}
-
else
-
{
-
hideOrShowInput("complete",true)
-
}
-
if (plPopulateExtra)
-
{
-
populateExtra(lcSource, lcDestination, true, true)
-
}
-
}
-
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
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.
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: -
// update the main address form with the correctly formatted, selected address.
-
parent.document.contactDetails.organisation.value = jsaddressList[num][0];
-
parent.document.contactDetails.address1.value = address[0];
-
parent.document.contactDetails.address2.value = address[1];
-
parent.document.contactDetails.address3.value = address[2];
-
parent.document.contactDetails.address4.value = address[3];
-
parent.document.contactDetails.town.value = jsaddressList[num][6];
-
parent.document.contactDetails.county.value = jsaddressList[num][7];
-
parent.document.contactDetails.postcode.value = jsaddressList[num][8];
-
This is inside a JavaScript function as far as I can tell.
Many thanks
Nathan
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
gits 5,390
Recognized Expert Moderator Expert
hi ...
what about calling:
within your populate function?
kind regards ...
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. -
// update the main address form with the correctly formatted, selected address.
-
parent.document.contactDetails.organisation.value = jsaddressList[num][0];
-
parent.document.contactDetails.address1.value = address[0];
-
parent.document.contactDetails.address2.value = address[1];
-
parent.document.contactDetails.address3.value = address[2];
-
parent.document.contactDetails.address4.value = address[3];
-
parent.document.contactDetails.town.value = jsaddressList[num][6];
-
parent.document.contactDetails.county.value = jsaddressList[num][7];
-
parent.document.contactDetails.postcode.value = jsaddressList[num][8];
-
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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:
------------------------------------------------------------
|
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(){
|
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);
|
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...
|
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
| |
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)
{
|
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...
|
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...
|
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 () {
...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |