I am creating a easy to use form web app that uses button presses to generate answers.
I would like the boxes to either show a colour or display a number and if possible both, then once press it then only shows the number or dims the other boxes so you can clearly see that you have pressed box 3 for example. I would like this to eventually to record what button is pressed and then be added to a form.
Any idea how I can create such buttons?
Give all the buttons a class and then something like:
$('.btnClass').click(function() {
$('.btnClass').css('opacity', 0.5);
$(this).css ('opacity', 1);
});
That will dim the non-selected buttons.
you could achive this by using radiobuttonĀ“s labels,
http://www.w3schools.com/tags/tag_label.asp
you hide the actual radiobuttons and style the labels like a traffic light or whatever,
so when you click the label it will automatically check the radiobutton.
with a bit of javascript/css and helperclasses you can easyily achive your desired effect (eg. blending out the other labels etc.)
Related
I'm having trouble finding javascript, HTML and/or CSS code that'll change the form based on the drop down menu. For example, the form is for adding a property and the drop down menu selections are single family, condo, apartment but they each have their own set of text boxes, menus and radio buttons. How can I achieve this?
What I have understand from your query is that , you have a from with some fields and you have a dropdown and you want that when ever your change selection in dropdown the form fields values must change accordingly right ?
If that is the issue , then it is very simple , first catch onSelectionChange event of dropdown and try to get selected value and once you get the selected value fill form fields by accessing them accordingly in a condition.Thanks
So I actually already had a piece of code I was fumbling with (http://jsfiddle.net/CYzsY/) for this question and it looks like its not working for me because its based on jQuery 1.7.1 and I'm linking to 1.10.2 in my code. Will make a new post accordingly. Thanks everyone!
I have a fiddle here: http://jsfiddle.net/ybZvv/43/
The problem I have is with the text inputs not changing. Please follow steps in fiddle below so you can see what is happening:
When you open fiddle, click on the "Add Question" button, this will add a table row copying the controls from the top into the table row.
In the table row click on the "Open Grid" and select button 5. You will see 5 letter buttons appear underneath from A-E.
Turn on all of the letter buttons by clicking on them (They should turn green to symbolize that the button is turned on)
You will see right at the bottom of the fiddle that it shows all of the text inputs of each value of the buttons which are turned on. This is fine.
The problem is here. If you go back into the table row and click on the "Open Grid" link again but this time choose "3", you will see the letters buttons change to A-C. Now letters D and E are not shown so they are turned off. But problem is that if you go to the bottom of the fiddle, the text input form D and E are still shown, they should be removed.
So my question is: what needs to be changed in the fiddle so that when the user changes their option type, it only displays the text inputs of those buttons which are still on after option has changed?
when you choose a option your code cleans the number box and the letters get changed ok.
The logic you apply to letters with class 'answerBtns answers' need to be apply also to the letter at the bottom. You must apply a class and do de process in javascript when get another choose.
I have a table which is filled with data from a database. Some javascript allows a user to select certain rows and take some actions. I allow users to click one row and then to shift click another row to create a group (as well as alt-click to select/deselect individual rows).
The problem is I don't like how the text highlights when they shift click. Is there some CSS setting or javascript/jQuery solution to disable the selectable text (cross browser preferablly or just in firefox).
If possible I also want to be able to let the user select text to copy and paste sometimes or inside a textbox form input inside the same table so I would like to be able to enable and disable the selecting of text somehow. Any ideas?
this should do the trick:
$('td').disableSelection();
example:
http://jsfiddle.net/GhfuJ/1/
Here's one way you could completely disable text selection:
$("selector").bind($.support.selectstart ? "selectstart" : "mousedown", function(event) {
event.preventDefault();
});
This is how jQueryUI implements its disableSelection() method.
You could tailor your selector to exclude textarea elements, or wrap code inside the event handler with an if block that evaluates a boolean that gets set under certain circumstances (For example, you could turn on booleans when the user is clicking or shift/alt + clicking).
I have a button. I click 3 times on
this button. I want show a yellow box
on first click, and hide the yellow
box and show a blue box instant of
that on second click , and hide blue
box and show a red box instant of blue
box on third click.
Is it possible with jQuery? How??
You can use the toggle() method, which takes multiple functions as parameters and executes one for each click (in sequence)
example at http://www.jsfiddle.net/4qsq4/
Keep in mind that this is a bit brute solution. If you could provide some of your HTML structure we could possibly automate this more.
Another realisation.
Use the toggle() event.
Example: http://jsfiddle.net/4xBmc/
When I have a set of either check boxes or radio buttons I often need to have an Other choice. This check box or radio button is very often accompanied by a text box where the user is supposed to fill out what this Other is.
How do you usually handle this set up? What kind of markup do you use? What do you require in your validation? Do you use java script for anything? For example:
How do you make the form accessible? Do you use and how do you use the label tag, for example.
Do you connect the check box and text box in any way with some javascript? For example, do you activate the text box when the check box is checked? Do you check or uncheck the check box automatically if the text box is filled out or cleared?
Do you let validation fail with error messages if the check box is checked but the text box is not filled out, or if the text box is filled out but the check box is not checked? Or do you just consider it not filled out and not checked?
Very unsure how to best deal with this issue, so any advice and examples are most welcome c",)
Typically when I have dynamic forms, I insert the input dynamically. That is, in the case of jQuery, I'll use .append('<input...') or some other similar function to actually insert the elements, and id it (or class it, depending), so that it can be easily .remove()-ed if the user decides they want to use another option instead. Validation is either handled via an onClick on an input button. If I'm feeling feisty, I'll go the AJAX route, and skip the <form> altogether.
I would definitely let the validation fail. They want "Other", and you want to know what "Other" is. If you don't care what Other is, then don't bother with the input box.
Edit: Might look something like this.
$('input[type="radio"]').click( function() {
if($(this).next().attr('name') != 'other' && $(this).attr('name') == 'other_input') {
$(this).after('<textarea name="other"></textarea>');
} else {
$('textarea[name="other"]').remove();
}
}
The click will react to any radio being clicked, and the if will make sure that it's only the "other" radio button that will react to the click, and that it will only react if there isn't already a textarea after it (so you don't get multiple textarea propogations).
On the processing side of things, you'll have to do a validation at first to see if other was checked, and to grab the input of the textarea if it was. You should probably use server-side validation for that.
Hope that gets you started.
I usually enclose my radio buttons in a label like this:
<label><input type=radio value=xyz name=stjames>Saint James</label>
this way the user can click on the text to trigger the button.
When deciding how to behave, I usually say to myself "what do you think the user expected when they did that..." and that often gives me the answer. So, upon click or Focus of the text box, turn on the radio that goes with it. This won't work if you've disabled the text box!
( ) US ( ) UK (*) Other [________________]
If the Other choice is a dangerous one (deleting data), though, I'd disable the text box until the user explicitly clicks Other. Then, the Radio drives the Text Box instead of the other way around. You want the user to have to go through another step in this case. It depends on the situation - think about what'll happen in each case.
I usually try to make it impossible or annoying for the user to do something 'wrong'. EG disable the OK button if something is inconsistent. Or, select the Other radio when the user types in text. If there's text in the text box but the radio buttons are set to something different, I'd usually just ignore the text. But if it's a serious/dangerous situation, you want to make sure the user's made up their mind; if you delete the text when the user chooses a different radio, that might piss them off but it might be appropriate if they should be careful.