/    Sign up×
Community /Pin to ProfileBookmark

form field verif. check script breaks in FFox

can someone see a reason this script would not work in FireFox:

[CODE]
function OnButton1() {
if (form.organization.value == “”) {
alert(“Please insert Organization.”);

form.organization.focus();

return false;
} else if (form.pos_title.value == “”) {
alert(“Please insert a Position Title.”);

form.pos_title.focus();

return false;
} else if (form.department.value == “”) {
alert(“Please insert a Department.”);

form.department.focus();

return false;
} else if (form.details.value == “”) {
alert(“Please fill Job Details.”);

form.details.focus();

return false;
}

var category = document.getElementsByName(‘category[]’);
var TotalLocationChecked = 0;
for (var i = 0; i < category.length; i++)
{
if (category[i].checked)
{
TotalLocationChecked = 1;
break;
}
}
if (TotalLocationChecked==0)
{
alert(“Please select at least one Category”);
category[0].focus();
return false;
} else {
document.form.action = “prev_post.php”
// document.form.target = “_blank”; // Open in a new window
// document.form.submit(); // Submit the page
}
}
[/CODE]

the image calling it is:
<input type=”image” src=”images/preview.gif” border=”0″ name=button1 onClick=”return OnButton1();”>

it doesn’t ‘Alert’ if a field is empty and it doesn’t open the new page is the fields are ok. it DOES work if i remove all the fields verif. and just call the action…

thanks for your help, whomever… :o)

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@KorApr 25.2008 — What is [B]form[/B]? The name of the FORM element?
Copy linkTweet thisAlerts:
@glenn_phpauthorApr 25.2008 — embarrasingly, it's

<form method="post" name="form" id="form" />

i think i took the action out because i'm using the javascript to call one of two actions...
Copy linkTweet thisAlerts:
@glenn_phpauthorApr 25.2008 — works fine in IE7...
Copy linkTweet thisAlerts:
@glenn_phpauthorApr 25.2008 — oh, i understand your question. yes...
Copy linkTweet thisAlerts:
@KorApr 25.2008 — ok, you must refer correctly the element upon the name

[COLOR="Blue"]document['form'][/COLOR].organization

[COLOR="Blue"]document['form'][/COLOR].department

and so on...

I used square brackets notation because you used a javascript reserved word: [B]form[/B]. Should have used, say, "myform", the refer can be written also as:

[COLOR="Blue"]document.myform[/COLOR].organization

[COLOR="Blue"]document.myform[/COLOR].department

All the document's HTML elements should have the [B]document[/B] object as "root"
×

Success!

Help @glenn_php 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 4.29,
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,
)...