Problem:
In the "Number of Answers" textbox, it should display the number 1, but it doesn't, it displays the number 2 and the reason it is displaying this number is that before the buttons changed, you selected 2 letter buttons, so it displays 2 in the textbox because you previously chose 2 letter buttons.
Now this is happening because of this code:
$('.answertxt', context).val(context.find('.answerBtnsOn').length > 0 ? context.find('.answerBtnsOn').length : '');,
in the $('.gridBtns').on('click', function() but I do need this code.
The reason I need this code is because lets say there is 7 letter buttons "A-G" and you turn on all the letter buttons, the textbox would display number "7", but if I change my mind and I want to only display 5 letter buttons "A-E", then the textbox would change from "7" to "5" as now only 5 buttons are turned on. That is why I need this code.
So my question is that if the user has clicked on the "Add" button, how can I get the number from the "Number of Answers" column within the row added be displayed in the textbox?
Below is the code I have where it is suppose to display the number within the textbox when the "Add" button is clicked on but it is over written because of the "$('#btn'+gridValues).trigger('click');" and in that code is the
$('.answertxt', context).val(context.find('.answerBtnsOn').length > 0 ? context.find('.answerBtnsOn').length : '');,
in the $('.gridBtns').on('click', function()
function addwindow(numberAnswer, gridValues, btn) {
$('#mainNumberAnswerTxt').val(numberAnswer);
$('#btn'+gridValues).trigger('click');
}
I think the important question is: why do you have to specify the number of answers AND the set of possible answers in the first place? That's redundancy. And if you want to have this sort of redundancy and keep it consistent at all times, you have to define constraints to do so, e.g. identify one of the things as primary -- either the textbox should always display the number of pressed buttons (and therefore be read-only) or (not really likely) the number of pressed buttons should always equal the number in the text box.
Allowing the user to edit the two independently is bound to cause inconsistency of the type you describe, even without the 'Add' button. I mean, I can type "2" and then go ahead and mark all the answers as possible.
I think you can add a custom attribute to the .gridBtns elements that specify who triggered the click button so that when the user click on the .gridBtns element you can use the $(this).attr("cutom attribute name") and use this value to check who triggered the action and you would react based on that.
Related
I'm making a typing game in JavaScript. I'm doing an assignment, and I've finished processing 1 and 2. but I don't understand the issues of 3 and 4. When I read the article on the net, but I couldn't achieve it with my tech.
The user sees the subject text, types the same value into the text box, and presses the OK button.
When the OK button is pressed, clear the text box and display the next subject.
Repeat steps 1 and 2 5 times.
When the ok button is pressed the 5th time, the total number of characters from the 1st to the 5th times, in which the theme and the value entered by the user are incorrect, is displayed on the screen.
Other than the mispelling mentioned, you are counting correct answers twice, it should be counted only in the keypress evenListener (it's also being counted in the check() function which makes it double
Then add in the end of the check() function:
if (CorrectCount >= 5) {
finish();
}
This will make the game stop after 5 OK's as intended.
In the check function, you misspelled the variable name. uestionList should be questionList
I'm soliciting your help.
I made a form that I'd like to use at my job. As i have to make reports all day long, I though it'd be faster to have a form already ready to be copied/pasted in the software I use.
Here is a fiddle of what I've done so far : http://jsfiddle.net/5j0mfero/
When I fill "description" field, it does write everything in the "Preview" textbox but I don't succeed for other textboxes and checkboxes.
Things are that I'd like it to be pre-formatted this way :
Description : //value of description's field
Equipment : // value of equipment
Tests : █ // value of checkbox
█ // value of checkbox
█ // value of checkbox
█ // value of textbox "other"
Option : // values of "option" checkboxes comma separated
Terminal : // values of checkboxes + textbox "other"
Is it possible to do it with jquery or javascript ?
If yes, how should I do ?
Then afterwards I'd add a button in order to copy the preview box.
Thanks for your answers.
Check out this fiddle :).
Also, click on the Generate Report button to get that formatted string you wanted instead because I couldn't think of way to have it dynamically generated every time any of the fields above get modified.
I am a novice when it comes to javascript and I need some help with a specific thing:
Make text appear in an input as I click on a button.
A bit of a situation: In a HTML form the user selects 2 tickets in a different input. Let's say each ticket is worth $5, I want the script to show the total price of the tickets in an input at the bottom.
Here is how the script should behave
First make a variable for the total price. You will then need to write a formulae that multiplies the first input by the price (In this case $5) and saves this number to the variable created previously. Finally document.write this variable into the second input
Background
I have a page that has 3 input elements which takes currency numbers
These input element of type number with jQuery handles which letting up to 2 decimal placing. If user tries to input 3rd decimal, it does not print which is great.
However...
Issue
When input already has valid 2d.p input such as 12.11 and wishes to highlight the field characters (such as click drag highlight to blue) to change/overwrite all, the jQuery handler think that its 3rd decimal input and does not print BUT what it actually needs to do is to overwrite the whole and start from the beginning.
So
Is there a way to check if the input field characters are highlighted?
I know that there is a way around this if my input has type="text" and just use selectionStart and selectionEnd BUT I want to keep it as type="number".
Code: jsfiddle DEMO
Any other suggestion to jQuery code handling 2 decimal place, I would appreciate
If I am understanding your issue correctly, try the following minimal update to detect if the user has 'highlighted' the input value:
if (CharAfterdot > 3 && !window.getSelection().toString()) { return false; }
So if a 'selection' is found via the above method (not empty / undefined) the code allows further input (in your case overriding via highlight).
Updated fiddle:
https://jsfiddle.net/qtr30w05/3/
My objective is to accumulate results of a multi-page questionnaire form into a summary page. Specifically I wish to take the selection from radio buttons and check boxes and place their values into another field on the summary page. This works fine when the radio button selections are numbers. I use the following script in the calculation pane (Custom calculation script) of the destination field of the summary page e.g.
var v1 = +getField("Hx.LBPWorst").value;
event.value=v1
The variable Hx.LBPWorst is a radio button with 11 buttons, 0-10 and the selected option is transferred to another field on the summary page without problems
My problem is that I wish to transfer text choices rather than numbers from a radio button E.g.
The radio button Hx.mech.prosit has four options “Worse”, “Better”, “NE”, “Varies”. The destination field for the selected option is a field with the format set to “None”. I have attempted to use the same structure i.e.
var v2 = +getField("Hx.mech.prosit").value;
event.value=v2
In this case the destination variable is filled with NaN i.e. Not a Number. I have read some of the questions and answers in this forum and apparently the problem is that radio buttons actually don’t store the selection as text. How can I achieve my objective and still use radio buttons (or check boxes)?
Change +getField to getField
var v2 = getField("Hx.mech.prosit").value;
The Unary plus (+) is changing the string to a number. When it can not convert it to a number, you get the NaN.