Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I recently laid out a fairly simple quiz question with jQuery (show / hide, addclass and a variable to count attempts and respond if attempts = 2), and I'm trying to figure out the best practice for replicating the same code on multiple questions. Would the best practice be to change all the variables for both the HTML layout and the jQuery? Or is there a more efficient way to add a second / third.. etc question?
Here's how I laid out the first question.
<form class="ra">
<div class="cor">
<input type="radio" name="question1" class="c1" />A. Choice A<span class="hiddencorr">Correct answer</span>
</div>
<div class="inc">
<input type="radio" name="question1" class="i1" />B. Choice B<span class="incorr">Your choice</span>
</div>
<div class="inc">
<input type="radio" name="question1" class="i2" />C. Choice C<span class="incorr">Your choice</span>
</div>
<div class="inc">
<input type="radio" name="question1" class="i3" />D. Choice D<span class="incorr">Your choice</span>
</div>
<div class="inc">
<input type="radio" name="question1" class="i4" />E. Choice E<span class="incorr">Your choice</span>
</div>
</form>
<p class="rationale1"><b>Rationale:</b>
<br />
<br /><span class="rattext">Explanation of what was done wrong.</span>
</p>
<button id="radiochk1" class="checkhide">Check your answer</button>
<button id="resetq1" class="reset">Reset</button>
JS / CSS & functionality in fiddle.
http://jsfiddle.net/YSSWL/97/
Class values related to initial style and layout typically should not differ among like elements (though those indicating state could). Instead, increment your name and ID attributes using jQuery, similarly to what you're doing now for class.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
You can see here:
How to find for .js (javascript)? This is from WooCommerce default coding. Coding from html via F12 "Your order". I copy the html and insert in Shipping page - it turns out badly. Could you help me? Thank you!
<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_flat_rate11" value="flat_rate:11" class="shipping_method">
<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_nova_poshta_shipping_method" value="nova_poshta_shipping_method" class="shipping_method">
<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_flat_rate10" value="flat_rate:10" class="shipping_method">
Before
<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_nova_poshta_shipping_method" value="nova_poshta_shipping_method" class="shipping_method">
After
<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_nova_poshta_shipping_method" value="nova_poshta_shipping_method" class="shipping_method" checked>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I am using materialize framework and i have to populate this form using java script. I am not sure how to access them in my js file
<div class="row col s10 offset-s1" id="questionArea" style="display:none">
<blockquote class="flow-text"> Select the capital of the country shown below.</blockquote>
<div class="input-field col s6">
Question <span id="quesTextSpan"></span><p>
<input name="qOptions" type="radio" id="optionId0" class="with-gap qOptionClass" />
<label for="optionId0"></label>
</p>
<p>
<input name="qOptions" type="radio" id="optionId1" class="with-gap qOptionClass" />
<label for="optionId1"></label>
</p>
<p>
<input name="qOptions" type="radio" id="optionId2" class="with-gap qOptionClass" />
<label for="optionId2">d</label>
</p>
<p>
<input name="qOptions" type="radio" id="optionId3" class="with-gap qOptionClass" />
<label for="optionId3"></label>
</p>
</div>
</div>
You can access the values of the radio buttons like this:
var radioVal = document.getElementById('optionId0').checked;
You can then perform logic on them by using conditionals and functions.
To gather them all quickly I would recommend doing this.
var radios = document.querySelectorAll('input[type="radio"]');
This will give you an array with each of the elements.
You may then go through and change the value to true or false depending on how you want to populate them.
Example)
radios[0].checked = true // Sets the first radio button to be on.
Edit)
To display the div use:
document.getElementById('questionArea').style.display = '';
To hide the div use:
document.getElementById('questionArea').style.display = 'hidden';
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
<form>
<input type="radio" name="gender" value="Male">Male </br>
<input type="radio" name="gender" value="Female"> Female
</form>
example: when I check male and then I will go navigation and choose clothing so it will sort out the things that will be shown in clothing are all male clothing vice versa
sample html
sample navigation after choosing male or female
This will help you
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<form>
<input id="male" type="radio" name="gender"value="Male">Male
<input id="female" type="radio" name="gender" value="Female">Female
</form>
<li>
<a id="accesory" href="accesroy">Accesory</a>
<a id="maleapparel" style="display:none" href="maleapparellink">Male Apparel</a>
<a id="femaleapparel" style="display:none" href="femaleapparellink">Female Apparel</a>
</li>
<---js--->
<script>
$(document).on('click','#male',function(){
$("#accesory").hide();
$("#femaleapparel").hide();
$("#maleapparel").show();
});
$(document).on('click','#female',function(){
$("#accesory").hide();
$("#maleapparel").hide();
$("#femaleapparel").show();
});
</script>
<---js--->
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Im trying to make a simple quiz like so:
I would like to use a custom alert box, not the usual JavaScript one. So just a div that appears with my message inside.
Apologies if I do not have more to work with than the screenshots - I've looked at many other questions and bits of scripts, but I'm really interested in something simple that can push me in the right direction.
Thanks!
You could try with JQuery. Then you could show or hide the divs simply by using $("#mydiv").show() or $("#mydiv").hide().
.correct{max-width:100px;opacity:0}
input:checked.right ~div.correct{position:relative;background-color:yellow;top:-20px;left:70px;opacity:1;}
<div >
Which country is commonly called the U.S.A ?<br>
England<input type="radio" name="one" value="UK" /><br>
America<input type="radio" name="one" value="US" class="right"/><br>
<div class="correct">Correct</div></div>
<div >
Which country is commonly called the U.S.A ?<br>
England<input type="radio" name="two" value="UK" /><br>
America<input type="radio" name="two" value="US" class="right"/><br>
<div class="correct">Correct</div></div>
<div >
Which country is commonly called the U.S.A ?<br>
England<input type="radio" name="three" value="UK" /><br>
America<input type="radio" name="three" value="US" class="right"/><br>
<div class="correct">Correct</div></div>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I am looking for a javascript that can check multiple checkboxes within a set group.
I am searching for something that would achieve this:
If checkbox group1 is checked checkbox 1,2,3,4,5 are checked.
I did not find a similar solution in Javascript please help me out!
here is a solution :
HTML :*
<input type="checkbox" onchange="check('1');" name="GRP" id="GRP1" />G1
<br>
<input type="checkbox" name="GRP-1" />1-G1
<input type="checkbox" name="GRP-1" />2-G1
<input type="checkbox" name="GRP-1" />3-G1
<input type="checkbox" name="GRP-1" />4-G1
<hr>
<input type="checkbox" onchange="check('2');" name="GRP" id="GRP2" />G2
<br>
<input type="checkbox" name="GRP-2" />1-G2
<input type="checkbox" name="GRP-2" />2-G2
<input type="checkbox" name="GRP-2" />3-G2
<input type="checkbox" name="GRP-2" />4-G2
<hr>
<input type="checkbox" onchange="check('3');" name="GRP" id="GRP3" />G3
<br>
<input type="checkbox" name="GRP-3" />1-G3
<input type="checkbox" name="GRP-3" />2-G3
<input type="checkbox" name="GRP-3" />3-G3
<input type="checkbox" name="GRP-3" />4-G3
JavaScript :
function check(grp_num)
{
var checks=document.getElementsByName('GRP-'+grp_num);
for(i=0;i<checks.length;i++){
checks[i].checked=document.getElementById("GRP"+grp_num).checked;
}
}