/    Sign up×
Community /Pin to ProfileBookmark

validation not working

Hi there,

I create a page to let me key in some customer information for booking, because one booking may have more than 1 customer, so i declare the entire customer info table as a variable, so can let me create how many customer i want to key in for this booking, in php i use loop to insert the data into DB, it was work fine, but when i try to do validation for the field, it totally not working, below is my code:

[CODE]
function validate_required(field,alerttxt)
{
with (field)
{
alert(field);
if (value==null||value==””)
{
alert(alerttxt);return false
}
else
{
return true
}
}
}

function validate_form(thisform)
{
var cond = parseInt(document.getElementById(“txt_amountCust”).value);
var name = “txtname_”;
var ic = “txtIc_”;
var addr = “txt_addr_”;
var poskod = “txt_poskod_”;
var phone = “txt_phone_”;
var hpnumber = “txt_hpnumber_”;

with (thisform)
{
for(var i=parseInt(1);i<=cond;i++)
{
if (validate_required(nama+i,”Name must be filled out!”)==false)
{
nama+i_.focus();
return false
}
if (validate_required(ic+i,”IC must be filled out!”)==false)
{
ic+i.focus();
return false
}
if (validate_required(addr+i,”Alamat must be filled out!”)==false)
{
addr+i.focus();
return false
}
if (validate_required(poskod+i,”Poskod must be filled out!”)==false)
{
poskod+i.focus();
return false
}
if (validate_required(phone+i,”Phone Number must be filled out!”)==false)
{
phone+i.focus();
return false
}
if (validate_required(hpnumber+i,”Other Phone must be filled out!”)==false)
{
hpnumber+i.focus();
return false
}
}
}
}
[/CODE]

i try to track the problem, and in my code

[CODE]
function validate_required(field,alerttxt)
{
with (field)
{
alert(field);
if (value==null||value==””)
{
alert(alerttxt);return false
}
else
{
return true
}
}
}
[/CODE]

i use alert(field) to track and found that field name that pass are correctly, and getting the error “value is no defined”, may i know is it i miss out anything, i was trying almost a day here just to find out this problem, any expert can help?

Thanks and best regard
Kc

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @kcwong13 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.21,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...