/    Sign up×
Community /Pin to ProfileBookmark

problem with focus()

hi,
i’m facing some difficulties when using the focus() function and was hoping if u could help. i have created the following form in html and this form’s validation in javascript. the form has more fields but with the one that follows i have the problem

<form name=”order” action=”order.php” method=”post” onsubmit=”return validate_order_form(order);”>
Code:
<input type=”text” maxlength=9 name=”afm”>
<input type=”submit” value=”Order” onSubmit=”return validate_order_form(order);”>
<input type=”reset” value=”Reset” name=”clear”>
</form>

<script language=”javascript”>
<!–

function afm(form){
var myStr= new String(form.afm.value);

if(form.afm.value!=”” && myStr.length!=9){
alert(“&#928;&#945;&#961;&#945;&#954;&#945;&#955;&#949;&#943;&#963;&#964;&#949; &#957;&#945; &#963;&#965;&#956;&#960;&#955;&#951;&#961;&#974;&#963;&#949;&#964;&#949; &#963;&#969;&#963;&#964;&#940; &#964;&#959; &#913;&#934;&#924; &#963;&#945;&#962;.”);
return false;

}
return true;
}
function validate_order_form(form)
{
var flag;

<!– if afm field is filled then check if it has 9 characters length –>
if(form.afm.value!=””){
flag=afm(form);
form.afm.focus();
return false;
}
return true;
}
//–>
</script>

the probem is that i cannot submit the data to the php file because of the focus(). when i removed the focus() it worked just fine. can u sugget me any way to fix this problem without removing focus?

thnx a lot
yona_t

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@bokehMay 31.2006 — [code=php]if(form.afm.value!="" && myStr.length!=9){[/code]That says: if the form is not empty and does not have a string length of 9 return false. That means the form would only submit if that field is empty.

By the way this is Javascript, not PHP.
Copy linkTweet thisAlerts:
@yona_tauthorMay 31.2006 — sorry, u r right. i just posted my thread here because it had a connection with php.

i used the following line
[CODE]if(form.afm.value!="" && myStr.length!=9){ [/CODE]
in order to check if the specific value is empty and if it;s length is other than 9 to alert the user so that he corrects the field

u dont have to reply to this i'll just make a thread to the javascript section

thnx for ur time and sorry for the inconvenience

yona_t
Copy linkTweet thisAlerts:
@bokehMay 31.2006 — What I was pointing out was the logic is reversed. [I]form.afm.value!=""[/I] returns true if the string contains a value and not if it is empty.
×

Success!

Help @yona_t 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.18,
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,
)...