/    Sign up×
Community /Pin to ProfileBookmark

Using JavaScript with forms

I’m having trouble with JS returning the value of radio buttons.
For instance it works one I have one radio button like this.

[QUOTE]

<html>
<head>
<title>Checking Out Radio Buttons</title>
<script language=”JavaScript” type=”text/javascript”>
function Alert() {
value=document.form1.condition.value
window.alert(value);
}
</script>
<body>
<form name=”form1″>
<p><b>Title: </b><input type=”text” name=”title” size=”20″>
</p>
<p><b>Author: </b><input type=”text” name=”author” size=”20″>
</p>
<p><b>Synopsis: </b><textarea name=”synopsis” cols=”50″ rows=”10″>
</textarea>
</p>
<p><b>Picture: </b><input type=”file” name=”picture”>
</p>
<p><b>Condition</b></p>
<p><b>Poor </b>
<input type=”radio” name=”condition” value=”poor”>

<input type=”button” value=”Submit” onClick=”Alert();”>
</form>
</body>
</html>

[/QUOTE]

And then it doesn’t work when I have 2 radio buttons like this.

[QUOTE]

<html>
<head>
<title>Checking Out Radio Buttons</title>
<script language=”JavaScript” type=”text/javascript”>
function Alert() {
value=document.form1.condition.value
window.alert(value);
}
</script>
<body>
<form name=”form1″>
<p><b>Title: </b><input type=”text” name=”title” size=”20″>
</p>
<p><b>Author: </b><input type=”text” name=”author” size=”20″>
</p>
<p><b>Synopsis: </b><textarea name=”synopsis” cols=”50″ rows=”10″>
</textarea>
</p>
<p><b>Picture: </b><input type=”file” name=”picture”>
</p>
<p><b>Condition</b></p>
<p><b>Poor </b>
<input type=”radio” name=”condition” value=”poor”>

<input type=”button” value=”Submit” onClick=”Alert();”>
</form>
</body>
</html>

[/QUOTE]

It says the value is undefined.

If you know what the problem is and how to fix it, it would be greatly appreciated.

Thanks again.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@TravisMathauthorMar 18.2005 — Well considering I didn't include the correct code I used when I used 2 radio buttons let me try again.

Here's the code I used:

<html>

<head>

<title>Checking Out Radio Buttons</title>

<script language="JavaScript" type="text/javascript">

function Alert() {

value=document.form1.condition.value

window.alert(value);

}

</script>

<body>

<form name="form1">

<p><b>Title: </b><input type="text" name="title" size="20">

</p>

<p><b>Author: </b><input type="text" name="author" size="20">

</p>

<p><b>Synopsis: </b><textarea name="synopsis" cols="50" rows="10">

</textarea>

</p>

<p><b>Picture: </b><input type="file" name="picture">

</p>

<p><b>Condition</b></p>

<p><b>Poor </b>

<input type="radio" name="condition" value="poor">

<p><b>Fair </b>

<input type="radio" name="condition" value="poor">

</p>

<input type="button" value="Submit" onClick="Alert();">

</form>

</body>

</html>
Copy linkTweet thisAlerts:
@Warren86Mar 18.2005 — Alert is a reserved word.

<html>

<head>

<title>Checking Out Radio Buttons</title>

<script language="JavaScript" type="text/javascript">

function dispAlert(){

nBtns = document.getElementsByName('condition');
for (i=0; i<nBtns.length; i++)
{
if (nBtns[i].checked == true){alert(nBtns[i].value)}
}


}

</script>

<body>

<form name="form1">

<p><b>Title: </b><input type="text" name="title" size="20">

</p>

<p><b>Author: </b><input type="text" name="author" size="20">

</p>

<p><b>Synopsis: </b><textarea name="synopsis" cols="50" rows="10">

</textarea>

</p>

<p><b>Picture: </b><input type="file" name="picture">

</p>

<p><b>Condition</b></p>

<p><b>Poor </b>

<input type="radio" name="condition" value="poor">

<p><b>Fair </b>

<input type="radio" name="condition" value="fair">

</p>

<input type="button" value="Submit" onClick="dispAlert();">

</form>

</body>

</html>
Copy linkTweet thisAlerts:
@Willy_DuittMar 19.2005 — [i]Originally posted by Warren86 [/i]

[B]Alert is a reserved word.



<html>

<head>

<title>Checking Out Radio Buttons</title>

<script language="JavaScript" type="text/javascript">



function dispAlert(){



nBtns = document.getElementsByName('condition');
for (i=0; i<nBtns.length; i++)
{
if (nBtns[i].checked == true){alert(nBtns[i].value)}
}


}

</script>

<body>

<form name="form1">

<p><b>Title: </b><input type="text" name="title" size="20">

</p>

<p><b>Author: </b><input type="text" name="author" size="20">

</p>

<p><b>Synopsis: </b><textarea name="synopsis" cols="50" rows="10">

</textarea>

</p>

<p><b>Picture: </b><input type="file" name="picture">

</p>

<p><b>Condition</b></p>

<p><b>Poor </b>

<input type="radio" name="condition" value="poor">

<p><b>Fair </b>

<input type="radio" name="condition" value="fair">

</p>

<input type="button" value="Submit" onClick="dispAlert();">

</form>

</body>

</html> [/B][/QUOTE]


Warren;

Did you just wake up from a coma??

Language was deprecated... OH... 8 YEARS AG0!!

[b]<Script Language=JavaScript>[/b]

Should be:

[b]<script type="text/javascript">[/b]

As well as... ALL attributes SHOULD BE quoted and ALL tags SHOULD BE written in lowercase...

Tsk, tsk... such sloppy advice... :rolleyes:

But what is truly sad... Is, these same things have been pointed out to you again and again but you're either too stubborn or too stupid to realize the errors of your ways and continue to offer such ignorant and malformed advice... ?

.....Willy
×

Success!

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