Javascript

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized ForumsWeb Design & DevelopmentJavascript

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old December 6th, 2011, 12:49 AM
carlbrooks carlbrooks is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 3 carlbrooks User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 50 sec
Reputation Power: 0
Buttons unselect problem

I included a jQuery handler for my dropdown menus so that when something is selected in the first dropdown menu, it will manipulate the options in the second dropdown menu. Now what the user does is pick the option type in the first dropdown (`OptionDropId`) menu and then in the second dropdown (`NumberDropId`) menu the user selects the number of answers wanted. Below that dropdown menu a list of buttons would appear and the user selects the number of buttons depending on how many the user has selected in the second dropdown menu.

Now let's say user clicks on two buttons and then changes the option type (first dropdown menu), then the buttons selected are still selected, I want the buttons to be unselected if the option type has changed.

This used to work but since I have included my `change` event handler to bind my jquery (this code is needed), it does not unselect buttons when the option type changes.

What do I need to do to fix this:

Below is my jquery and function of select and unselect buttons:
Code:
    $(document).ready(function ()
    {
        var OptDrop = new Array();
    
        OptDrop.abc = ["",1,2];
        OptDrop.abcd = ["",1,2,3];
        OptDrop.abcde = ["",1,2,3,4];
        OptDrop.trueorfalse = [1];
        OptDrop.yesorno = [1];
    	    
        $("#optionDropId").change(function ()
        {
            var selectedValue = $(this).val();
            $("#numberDropId").html("");
            $.each(OptDrop[selectedValue], function (x, y)
            {
                $("#numberDropId").append($("<option></option>").attr("value", y).html(y));
            });
        }); 
    
        $("#optionDropId").change();
    });       
    
    var currenttotal=0;
    function getButtons()
    {
    	document.getElementById("answerA").className="answerBtnsOff";
    	document.getElementById("answerB").className="answerBtnsOff";
    	document.getElementById("answerC").className="answerBtnsOff";
    	document.getElementById("answerD").className="answerBtnsOff";
    	document.getElementById("answerE").className="answerBtnsOff";		
    	document.getElementById("answerTrue").className="answerBtnsOff";
    	document.getElementById("answerFalse").className="answerBtnsOff";
    	document.getElementById("answerYes").className="answerBtnsOff";
    	document.getElementById("answerNo").className="answerBtnsOff";
     
    	currenttotal=0;
    }
    
    function btnclick(btn)
    {
     	if(document.getElementById("numberDropId").value=="")
     	{
    	 	alert('You must first select the number of answers you require from the drop down menu');
    	 	return false;
    	}
    	if (btn.className=="answerBtnsOn")
    	{
    		btn.className="answerBtnsOff";
    		currenttotal--;
    		return false;
    	}
     	if(document.getElementById("numberDropId").value==currenttotal)
     	{
     	 	alert('You are not allowed beyond the limit of the number of answers you require, deselect other button');
     		return false;
     	}
    	if (btn.className=="answerBtnsOff")
    	{
    		btn.className="answerBtnsOn";
    		currenttotal++;
    		return false;
    	}
     
    }


Html code is below:
Code:
    <form id="enter" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" onsubmit="return validateForm(this);">
      <table id="optionAndAnswer">
        <tr>
          <th colspan="2">
            Option and Answer
          </th>
        </tr>
        <tr>
          <td>Option Type:</td> 
          <td>
            <select name="optionDrop" id="optionDropId" onChange="getDropDown()">
              <option value="">Please Select</option>
              <option value="abc">ABC</option>
              <option value="abcd">ABCD</option>
              <option value="abcde">ABCDE</option>
              <option value="trueorfalse">True or False</option>
              <option value="yesorno">Yes or No</option>
            </select>
          </td>
       </tr>
       <tr>
         <td>Number of Answers:</td>
         <td>
           <select name="numberDrop" id="numberDropId" onChange="getButtons()">
           </select>
         </td>
       </tr>
       <tr>
         <td>Answer</td>
         <td>
           <input class="answerBtns" name="answerAName" id="answerA" type="button" value="A" onclick="javascript:btnclick(this);"/>
           <input class="answerBtns" name="answerBName"	id="answerB" type="button"   value="B" onclick="javascript:btnclick(this);"/>
           <input class="answerBtns" name="answerCName" id="answerC" type="button"   value="C" onclick="javascript:btnclick(this);"/>
           <input class="answerBtns" name="answerDName" id="answerD" type="button"  	value="D" onclick="javascript:btnclick(this);"/>
           <input class="answerBtns" name="answerEName" id="answerE" type="button"   value="E" onclick="javascript:btnclick(this);"/>
           <input class="answerBtns" name="answerTrueName" id="answerTrue" type="button"  	value="True" onclick="javascript:btnclick(this);"/>
           <input class="answerBtns" name="answerFalseName" id="answerFalse" type="button"   value="False" onclick="javascript:btnclick(this);"/>
           <input class="answerBtns" name="answerYesName" id="answerYes" type="button"   value="Yes" onclick="javascript:btnclick(this);"/>
           <input class="answerBtns" name="answerNoName" id="answerNo" 		type="button" value="No" onclick="javascript:btnclick(this);"/>
         </td>
        </tr>
      </table>
    </form>

Reply With Quote
Reply

Viewing: Tutorialized ForumsWeb Design & DevelopmentJavascript > Buttons unselect problem


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap