/    Sign up×
Community /Pin to ProfileBookmark

Input Validation HELP !!!

Hi,

My first time to post on this forum, hope that you guys can help me.

Below is the form that I need to make it work for the input validation. I have no problem making both BUSINESS NAME and STATE/CITY work for the javascript validation.

The only problem I have is the STATE/CITY (within one field). By Default, I have “CA,” <input value=”CA”> on it without a city. I need my visitor to enter the city before click on the search button.

My question is: How can I make the javascript still validate the STATE/CITY even with the value =”CA” presented. If I remove the value=”CA”, then everything works fine. Box pops up asking them to fill both fields. Once I put the state as a value, then javascript for the STATE/CITY won’t pop up. Can anyone show me how to get it work. Thanks. ? ? ? ?
————————–

Business Name: XYZ Cafe
State and City: CA,

[SEARCH BUTTON]
————————–

<script language=”javascript”>

function fnValidate(){

if(document.frmBusinessSerch.bname.value==””){
alert(“Please enter the Business Name.”)
document.frmBusinessSerch.bname.focus()

return false
}

if(document.frmBusinessSerch.statecity.value==””){
alert(“Please enter the State & City”)
document.frmBusinessSerch.statecity.focus()

return false
}

}
</script>

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@NedalsJan 08.2008 — Your best bet is to seperate the city and state into two seperate fields.

Failing that, you need a RULE to determine if the city was entered.

SAY: state must be followed by a comma-space-cityname.

Now you could use a regex or a split function to check for both.
Copy linkTweet thisAlerts:
@villin_zhouJan 08.2008 — I think you also need to check the value whether it equals to "CA" or not.

like this:

var scinput = document.frmBusinessSerch.statecity;

if(scinput.value=="" || scinput.value=="CA"){

alert("Please enter the State & City")

scinput.focus()

return false

}
Copy linkTweet thisAlerts:
@NedalsJan 08.2008 — I think you also need to check the value whether it equals to "CA" or not.[/QUOTE]
One would think it could be any state, not just CA. ?
Copy linkTweet thisAlerts:
@juno612authorJan 08.2008 — First of all, thank you for all of your help ?

No, this is only for CA. No other state will be enter. Actually I want to remove the CA totally, but when I do that. Search result doesn't come out right with only city on it. Our database only contain businesses within CA. See actuall page here: goyuno dat com/add-a-business-search.php
Copy linkTweet thisAlerts:
@NedalsJan 08.2008 — Actually I want to remove the CA totally, but when I do that. Search result doesn't come out right with only city on it. Our database only contain businesses within CA. See actuall page here: goyuno dat com/add-a-business-search.php[/QUOTE]
You could remove it from the page and hard code it back-in with PHP before the database search.
Copy linkTweet thisAlerts:
@juno612authorJan 08.2008 — You could remove it from the page and hard code it back-in with PHP before the database search.[/QUOTE]

I am not a programmer. I just hope that I could just editing the existing javascript to get by.
Copy linkTweet thisAlerts:
@NedalsJan 08.2008 — RULE:

input must be 'CA,city' where city is 4 or more chrs.

You can change that to whatever you want
<i>
</i> if (!/CA,.{4}/.test(document.frmBusinessSerch.statecity.value)){
alert("Please enter the State &amp; City");
document.frmBusinessSerch.statecity.focus();
return false;
}
Copy linkTweet thisAlerts:
@juno612authorJan 08.2008 — Great, it works. That save me some money ?

Please allow me to ask one quick question, how can I make it ca and CA both satisfy the javascript statement. Currently only CA is satisfy. Thanks.
Copy linkTweet thisAlerts:
@NedalsJan 09.2008 — if (!/CA,.{4}/[b]i[/b].test(document.frmBusinessSerch.statecity.value)){
Copy linkTweet thisAlerts:
@juno612authorJan 09.2008 — Work perfectly fine. Can't ask for more !!! ? ? ? A BIG THANKS TO ALL YOU GUYS SPECIALLY NEDALS.

Realize that you located at up north, hopefully we can expand to north ca next year and hope you will join us there. Take Care.
×

Success!

Help @juno612 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.5,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...