Given:
1. query authors and books from database.
2. display the results in select drop-down boxes with <cfoutput query="queryName" group="groupName">
3. the default of each drop-down box is blank.
Question: How can I validate the select drop-down boxes and only one book can be selected when submiting the form?
Here is the code:
<cfquery name="queryName" datasource="…">
select author, book
from tableName
…
</cfquery>
/* display the results grouped by authors and all the books each author wrote are in a drop-down box */
<form action="actionPage" method="post" name="formName">
<cfoutput query="queryName" group="author">
<b>#author#</b><br>
<select name="book">
<option value=""></option>
<cfoutput group="book">
<option value="#book#">#book#</option>
</cfoutput>
</select>
</cfoutput>
<input type="submit" name="submit" value="View this book">
</form>
/* when viewing the source, it looks like the following */
Author1
<select name="book">
<option value=""></option>
<option value="author1_book1>author1_book1 </option>
<option value="author1_book2>author1_book2 </option>
<option value="author1_book3>author1_book3</option>
</select>
Author2
<select name="book">
<option value=""></option>
<option value="author2_book1>author2_book1 </option>
<option value="author2_book2>author2_book2 </option>
<option value="author2_book3>author1_book3</option>
</select>
Author3
…
<input type="submit"...>
...
You can see from the source that all form elements "select" have the same name "book". How can I validate them? I hope to write a javascript function to validate them and only one book can be selected when submitting the form.
Any suggestions…
Thanks in advance…
1. query authors and books from database.
2. display the results in select drop-down boxes with <cfoutput query="queryName" group="groupName">
3. the default of each drop-down box is blank.
Question: How can I validate the select drop-down boxes and only one book can be selected when submiting the form?
Here is the code:
<cfquery name="queryName" datasource="…">
select author, book
from tableName
…
</cfquery>
/* display the results grouped by authors and all the books each author wrote are in a drop-down box */
<form action="actionPage" method="post" name="formName">
<cfoutput query="queryName" group="author">
<b>#author#</b><br>
<select name="book">
<option value=""></option>
<cfoutput group="book">
<option value="#book#">#book#</option>
</cfoutput>
</select>
</cfoutput>
<input type="submit" name="submit" value="View this book">
</form>
/* when viewing the source, it looks like the following */
Author1
<select name="book">
<option value=""></option>
<option value="author1_book1>author1_book1 </option>
<option value="author1_book2>author1_book2 </option>
<option value="author1_book3>author1_book3</option>
</select>
Author2
<select name="book">
<option value=""></option>
<option value="author2_book1>author2_book1 </option>
<option value="author2_book2>author2_book2 </option>
<option value="author2_book3>author1_book3</option>
</select>
Author3
…
<input type="submit"...>
...
You can see from the source that all form elements "select" have the same name "book". How can I validate them? I hope to write a javascript function to validate them and only one book can be selected when submitting the form.
Any suggestions…
Thanks in advance…