Validating A Questionnaire Form? - javascript

My knowledge of JS is very limited and i need help in validating this form so its like the previous questionnaire they had which you can see on this URL
Is it best to use a jQuery plugin or Javascript? I'm trying to get it so when you select one checkbox per question you have a score appearing in bottom right hand corner and if you get the answer right the score increments by 1.
Probably the biggest thing I have done in JS so far. Any pointers or suggestions? Advice would be appreciated.
Current new form here.

I'd use jQuery or server side validation. Also, change your check boxes to groups of radio buttons, that way it's only possible to select one because of the way radio buttons work.

i've managed to sort this problem out - wrote an on click function and like created variables for the score and incremented this on click if the answer is correct which was then spanned in to a div that was setup.
Took ages to do but got there in the end :)

Related

Button OnCreate asset/resource at a different activity

Hello I have asked this question before but perhaps it wasn't clear or was deemed irrelevant but I need to figure out how to make a button OnClick create a button on another XML layout.
I am very new to java and coding in general and have looked for the past few days but can not find any information on how I would go about this.
The closest I could get was another users question on stackoverflow where the method of keeping the button I want to create invisible and having it switch visibility OnClick of original button, but this isn't feasible.
While this method would work for the single button I need to click to generate the other button, the place it would generate it will also generate a different variety of buttons from other sources. The only way this seems possible is to have the dozens of invisible buttons from each source already stored there and that doesn't seem like the most logical way to approach it code wise.
I would greatly appreciate any help in this area, I'm not expecting anyone to show me how it's done or write me sample code if you could simply nudge me in the direction of an online guide,tutorial or information source I'd be very grateful,
Thanks for your patience.
Creating Button programmatically and adding to the LinearLayout.
//First get the reference of LinearLayout where you need to add the buttons.
LinearLayout ll=(LinearLayout)findViewbyId(R.id.llayout);
// Layout Param
LayoutParams param = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
/* This line of code to add the button in layout (implement your own logic i.e how many time you need to add the button and at which condition you need to add).*/
Button button = new Button(Context);
button.setText("dynamic button 1");
ll.addView(button,param);
Hope this achieve your goal.

How do I build a multi-stage web form?

I'm trying to build a webform that has multiple stages. I'm patterning it off of the Stack Overflow / Stack Exchange flagging webform. The problem is, I'm not sure how to trigger the "next stage" action.
To illustrate, if one wants to flag a question on Stack Overflow, you click flag and then a popup prompts you to make a choice. If you choose the second option ("it doesn't belong here, or it is a duplicate") the form automagically takes you to a second screen.
First screen:
Upon click, it auto-redirects to:
The problem is that I don't know what the underlying trigger is. How does clicking that radio button send the end user to the next screen?
I tried checking the source, but I have a feeling I'm only seeing half the picture:
No amount of HTML tutorials I find have any practice example similar to this. I suspect this is JavaScript, but I can't find the linked .js file that would trigger these actions.
So: How does the webform auto-redirect upon click? As a follow-up, if it's using JavaScript, is there an HTML/CSS-only workaround I can use?
It might help to think about this at a lower level than frameworks. There are two ways one could make a multi-stage form.
The first (and generally older) way is to store the state on the server. Each stage of the form is actually a separate form, and the client's progress through the questionnaire is kept on the server (for example, as part of the session data).
The second way (the more modern one) is to use JavaScript, as you suspected. There is actually very little black magic in this case, and no auto-redirects on clicks at all. All you do is have one very long form where you show/hide some of the elements depending on the user's selections (of course, you could have multiple <form> elements which you show/hide).
Well, I'd use some sort of jQuery wizard plugin and adapt it to my needs. I did it very recently and it wasn't that hard. You should try SmartWizard 3.0, it's pretty active, the last release was about 2 months ago and the coders answered my questions pretty fast.
Here it is: https://github.com/mstratman/jQuery-Smart-Wizard
You can trigger the wizard to advance to the next step linking an event to the action of clicking the radio button.
Good luck :)

adding a text input field through js or jQuery when clicking on another input field in rails 3

I'm building a nested form in rails 3.1 and instead of pressing the "add" button i want to automaticly add an input field when typing text in an empty input field (just like making a question in facebook and adding poll options). But i also want to only add a field if there are characters typed in the field if the characters are removed the extra field should also be removed.
I am working with rails 3.1 and so jQuery and jquery-rails are included in my gem, i don't know coffee script yet.
it's really easy.
Just tap into the focus() event handler and add textboxes as you go along.
I have created a simple demo for you here: http://jsfiddle.net/mcVnN/
Warning: clicking any textbox will add a new textbox here. If you want to add new textbox ONLY on last textbox focus, just compare the id.
If you have any doubts let me know.
Cheers
--
Sorry, did not read your full question, my mistake.
I have put together some quick code http://jsfiddle.net/mcVnN/12/ again on jsfiddle, but you might want to change it to suit your needs.
I was going through my answers a now and realized I had left you in the middle of nowhere.
Took some time to completely re-write my answer - the above answer is a lot buggier, you are better off using the :last selector than manually trying to keep track of the last text box yourself.
See my rewrite here: http://jsfiddle.net/mcVnN/29/
I have also added a max text box count that you can change easily to configure how many textbox you want users to be able to add.
Please replace the above code with this one, if you are using the above one at all.
Thanks.

getting a radio button dynamically with jquery

I have tried this for too long... too big for me. I need a little help here.
I have a page with products. each product got 3 sizes (normal, big, special)
The user is selecting radio button to choose the size and then hits the "add to cart".
I am trying to get the value he chose, but without any success. Right now I found that jQuery is almost working for me.
If i write this down:
selected_val = $("input[name='sizeof75']:checked").val();
I am getting to right value of group named sizeof75. But since it changes dynamically, i am looking for a way to migrate the field name into this. I mean something like this:
selected_val = $("input[name='"+field_name+"']:checked").val();
any help will be aprreciated.
Thank you
Sorry,
this question is not relevant... just had a syntax problem...

Dynamically add input boxes into form?

What I am trying to do is very similar to this question:
Using jQuery to dynamically add form fields (or fieldsets) based on a dropdown box value
Specifically, I want to use a drop down box value to add that number of input boxes to a fieldset.
I do not know jQuery so the answer I am linking to hasn't answered my question, I would like to know how to do this in JavaScript?
There are lots of instructions on how to use JQuery. I suggest that you go to http://docs.jquery.com to learn it rather than looking here for a specific answer to your question. Spending the time to figure it out for yourself will be far more useful than a copy-paste answer.
You'll follow some basic steps. Tackle each one individually.
Read the value from the drop-down when it changes.
Find the element to contain the new input boxes.
Loop through the number of values
Insert the appropriate HTML for each loop iteration.

Categories