/    Sign up×
Community /Pin to ProfileBookmark

A simple alert window function problem

Hi!

On my page the user chooses some options. I made the alert window so that if the option is not chosen and the user executes the form it pops, saying: “option not chosen.” The options are choosed with the help of radio buttons (<input type=radio>).

The function:

<script language=”JavaScript”>
function zapolnenie_confirmation()
{
if (formaddch.company.value==null)
{
alert(“Choose Company Name”)
return false;
}
}
</script>

However, the script calls up the alert window even when the radio button is checked. What may be the problem?

By default, the value of the $company variable is 0(zero). When I try to write “formaddch.company.value==0” – it doesn’t work at all.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@yearbassAug 16.2005 — Actually when you use radio button, the radio button collection you have is an array. So if you want to check the value of user input, you must loop trhough the array to check is the item checked.

This is an example :

[CODE]<html>
<head>
<title>Just an example</title>
<script language="javascript">
function showChoose ()
{
for (var z=0; z<document.formaddch.company.length; z++)
{
if (document.formaddch.company[z].checked == true)
{
alert("You choose " +document.formaddch.company[z].value);
return true;
}
}
alert("Choose Company Name")
return false;
}
</script>
</head>

<body>

<form name="formaddch">
Choose Company Name: <br>
<input type="radio" name="company" value="ABC Company">ABC Company<br>
<input type="radio" name="company" value="DEF Company">DEF Company<br>
<input type="radio" name="company" value="GHI Company">GHI Company<br>
<input type="button" value="Pick" onclick="showChoose()">
</form>

</body>
</html>[/CODE]
Copy linkTweet thisAlerts:
@Louigi_VeronaauthorAug 16.2005 — Thanks! I'll try that.
Copy linkTweet thisAlerts:
@Louigi_VeronaauthorAug 16.2005 — Thank you very much! It worked! ?
Copy linkTweet thisAlerts:
@Louigi_VeronaauthorSep 02.2005 — what about the same problem, but when checkboxes involved. If not a single checkbox is checked, there should be a warning. I figured out with your help the radio buttons, but can't understand how to work with checkboxes - length certainly doesn't work here.
×

Success!

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