By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 816 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

Javascript error capture

P: n/a
HI All,

I'm in need of a lttle help as my javascript is almost non-existent.
Below is some code I have that alerts the user if they have not
selected a radio button. It also contains code alerting the user to
what they have selected.

I would like just the alert if they don't select a radio button but for
the life of me I'm unable to edit the javascript.

snip..............................
<script type="text/javascript">

function checkRadio(field)
{
for(var i=0; i < field.length; i++) {
if(field[i].checked) return field[i].value;
}
return false;
}

function checkForm3(form)
{
if(radioValue = checkRadio(form.pagetemplatename)) {
alert("You selected " + pagetemplatename);
} else {
alert("Incomplete Form: You must select a page layout to
continue");
}
return false;
}

</script>
snip..............................

and form code

snip..............................

<form action="index.cfm?fuseaction=page1" method="post"
action="/javascript/validate/" onSubmit="return checkForm3(this);">

this is the radio button:

snip.............................
<cfoutput>
<input type="radio" name="pagetemplatename"
value="#currentTemplate.objectID#" <cfif
isDefined("form.pagetemplatename") and form.pagetemplatename eq
currentTemplate.objectID> checked=checked</cfif>>
&nbsp;#currentTemplate.objectName#<br />
</cfoutput>
snip..............................

Thanking you in advance

Trevor

Jan 27 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I'll answer my own question after finding another solution in case
someone else is searching for a similar problem.

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin

function validate() {

var theMessage = " ATTENTION";
var noErrors = theMessage
var radioCheck = false;
for (i = 0; i < document.form1.pagetemplatename.length; i++) {
if (document.form1.pagetemplatename[i].checked)
radioCheck = true; }
if (!radioCheck) {
theMessage = theMessage + "\nYou need to select a page layout";
}
if (theMessage == noErrors) {
return true;

} else {
alert(theMessage);
return false;
}
}
// End -->
</script>

the form has:

<form action="index.cfm?fuseaction=page1" name="form1" method="post"
onSubmit="return validate(this);">

Radio button name I'm using name="pagetemplatename"

HTH someone.

Jan 27 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.