Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

i want to validate against the dropdown fields usrchoices which repeat

Status
Not open for further replies.

sydhussain2010

Programmer
Feb 22, 2012
3
AE
i want to validate against the dropdown fields usrchoices which repeat depends upon the data recordsets....Thanks in advance

<script language="JavaScript"><!--
function validating(validate) {
if (form.usrchoices.selectedIndex == 0) {
alert('Please select all Questions');
document.getElementById("validate").reset();

return false;

}
return true;
}
//--></script>

<form action="submitsurvey.asp" method="post" name="validate" id="validate" onSubmit="return validating()">
<% Do while Recordset_questions.EOF %>
<select name="usrchoices" id="usrchoices">
<option value="" selected>Select Choices</option>
<option value="Y">Yes</option>
<option value="N">No</option>
<option value="IDK">I Dont know</option>
</select>
<%Loop%>
</form>
 
I don't know how many iterations you expect to have but all of your selects will have the same name and id. You need to make them unique using your server side language.

Please post the html this template produces.

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Hi Lyndon,

First of all Thanks a Lot for your reply...actaully the repeatition depends upon the question exist in database, if user choose mathamatics and if the questions in database are 5 then page displays 5 dropdown menus where user select the answer from dropdown menu for each question.

The following Dropdown menu will appears infront of each question for user to select.

<select name="usrchoices" id="usrchoices">
<option value="" selected>Select Choices</option>
<option value="Y">Yes</option>
<option value="N">No</option>
<option value="IDK">I Dont know</option>
</select>

And we need user to must select from the drop down menu for each question so if there is 5 questions then user must select 1 item from every dropdown menu. which means 5 questions = 5 answers

if 5 questions = 4 answers
then the unanswered dropdown menu field must be highlighted and form must not be submitted.

Thanks again for your kind help
syed
 
Each <select> element needs to have a unique id/name. Such as,
form.usrchoices0.selectedIndex == 0
form.usrchoices1.selectedIndex == 0
form.usrchoices2.selectedIndex == 0
These form elements have unique names...

I don't know the server side language you're using so I can't show you how exactly but it will be something like:
Code:
<% Do while Recordset_questions.EOF %>
    <select name="usrchoices%Recordset_questions.currentrow%" id="usrchoices%Recordset_questions.currentrow%">
          <option value="" selected>Select Choices</option>
          <option value="Y">Yes</option>
          <option value="N">No</option>
          <option value="IDK">I Dont know</option>
        </select>
<%Loop%>

After the html is producing unique id's/Names for the selects you can work on a strategy to check the "selectedIndex" value of the select elements with an id/name beginning with the string "usrchoices"...

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Dear Lyndon,

Kindly can you write for me the javascript code to validate usrchoices, if you send the full solution by fix the full code, it will be a reference for me in future...And Thanks a million for your kind help.

Best Regards
Syed
 
You need to fix your server side code to give every select element a unique name and then post your client side HTML. Then I can help you.

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top