[thelist] Javascript question

Chris Blessing webguy at mail.rit.edu
Tue Jan 22 09:18:14 CST 2002


Josh-

A number of things... first off, you forgot the initial curly bracket for
the function.  It should be "function validate(){".  Also, you have to check
the value for a select box quite a bit differently than that of a form
field.  Selects are actually just arrays, so the name you give to the box
itself (in this case, board_decision) is really the name of an array
containing a bunch of indexed values (those would be the <OPTION>
components).  So in order to get the value for the select box, you have to
check this:

document.form.selectbox[document.form.selectbox.selectedIndex].value

This goes into the array and grabs the selectedIndex value from the array
(whatever value the user selected on the form).

Here's the code I got working (watch for wrap):

function validate(){
	with(document.disposition){
		if (board_decision_comments.value == '' &&
board_decision[board_decision.selectedIndex].value == 'Denied' ) {
			alert ("Please enter reason for denial.");
			return false;
		}
	}
}

Chris Blessing
webguy at mail.rit.edu
http://www.330i.net

> -----Original Message-----
> From: thelist-admin at lists.evolt.org
> [mailto:thelist-admin at lists.evolt.org]On Behalf Of josh
> Sent: Tuesday, January 22, 2002 10:07 AM
> To: thelist at lists.evolt.org
> Subject: [thelist] Javascript question
>
>
> Here is a simple function that I can't get to work.  Can you find my
> mistake?
>
> <head>
> <script language=Javascript>
>
> function validate()
>
> 	if (document.all.board_decision_comments.value == '' &&
> document.all.board_decision.value == 'Denied' ) {
> 	alert ("Please enter reason for denial.")
> 	return false
> 	}
> }
> </script>
>
> </head>
> <body>
> <form name="disposition" action=test.asp method=post onSubmit="return
> validate()">
> <select name='board_decision'>
> <option value='No Decision'>No Decision
> <option value='Approved'>Approved
> <option value='Denied'>Denied
> </select>
>
> <textarea name=board_decision_comments></textarea>
> </form>
> </body>
>
> </body>
>
> Thanks,
> Josh
>
>
> --
> For unsubscribe and other options, including
> the Tip Harvester and archive of TheList go to:
> http://lists.evolt.org Workers of the Web, evolt !





More information about the thelist mailing list