Re: how to update form after a user select a choice

2018-03-31 Thread xueqi dong
Hi thanks for advice. Though could you please provide an example somewhere?
my application probably needs to use javescript once  - it is a bit hard to
learn javascript from the beginning...

...
Xueqi Dong
Teaching Fellow, Economics group, Newcastle University Business School
5 Barrack Road, Newcastle, NE1 4SE, UK
Tel: +44  7780113210
Email: xueqidon...@gmail.com
Linkedin: https://sites.google.com/site/xueqidotdong/home

On 31 March 2018 at 13:02, Jani Tiainen <rede...@gmail.com> wrote:

> Hi,
>
> You need to write a piece of javascript that attaches to your radio
> buttons to call some javascript function to do what ever you want to happen.
>
> You can use js libraries like jquery to make things easier.
>
> 31.3.2018 14.15 "xueqi dong" <xueqidon...@gmail.com> kirjoitti:
>
>
> <https://lh3.googleusercontent.com/-R_HFbMboDMs/Wr9ptIsjQQI/AwQ/qfzbfcmpuGEWKAtCHo1vDu-ehVHkmF_PwCLcBGAs/s1600/VwH9Q.png>
> Hi, I would like to achieve the function as shown in the picture above.
> When an user click the radio button Lottery 1, Lottery 1 in the table above
> will become highlighted by colour yellow. When the form is initially
> rendered, neither lotteries are highlighted.
>
> I googled this and it seems that this has to be done on the client side
> and has little to do with Django. But I am not sure how to track the value
> of the selected choice in html. I know I can get the value of the submitted
> choice use forms.cleaned_data in views.py.
>
> In my form.py I have
>
> class AnswerForm(forms.Form):
> ANSWER_CHOICES = (
> (1, 'Lottery 1'),
> (2, 'Lottery 2'),
> )
> answer = forms.ChoiceField(choices=ANSWER_CHOICES, 
> widget=forms.RadioSelect)
> question = forms.IntegerField(widget=forms.HiddenInput)
>
>
> In problems.html template I have
>
> 
> 
>
>
>
> Please make a choice between two lotteries.
> Which lottery do you want choose   
>
>
>
>  
>   Two lotteries
>
> 
> "green">
>  
>
> State 1
>State 2
>State 3
>  
>
>  
> Lottery 1
> {{ problem.0 }}{{ sltlottery }}
>  {{ problem.1 }} 
>  {{ problem.2 }}
>  
>
>
> Lottery 2
>  {{ problem.3 }} 
>   {{ problem.4 }} 
>   {{ problem.5 }} 
>  
>
>   
>
>
>
>
>
> 
> {% csrf_token %}
> {{ form.as_p }}
> 
> 
>
>
> It looks like i need a logic statement like the following :  if selected
> choice =1, colour 1= "yellow", colour 2= "white"  else: colour 2= "yellow",
> colour 1= "white"
>
> There are two crucial steps I am not sure how to do.
>
> First, after an user select on choice by click the Radio button, how can I
> track the associated value?  For example, when Lottery 1 is selected, I
> need selected choice =1.
> Second, what is the easiest way to set write the logic statement in html?
> I am even not quite sure where to put the logic statement...
>
> Any help would be much appreciated!
>
> Xueqi
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/3bca5139-ff0c-4124-a937-947b33bd2c4c%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/3bca5139-ff0c-4124-a937-947b33bd2c4c%40googlegroups.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/django-users/sQDVzoL6D_0/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAHn91o

how to update form after a user select a choice

2018-03-31 Thread xueqi dong



Hi, I would like to achieve the function as shown in the picture above. 
When an user click the radio button Lottery 1, Lottery 1 in the table above 
will become highlighted by colour yellow. When the form is initially 
rendered, neither lotteries are highlighted.

I googled this and it seems that this has to be done on the client side and 
has little to do with Django. But I am not sure how to track the value of 
the selected choice in html. I know I can get the value of the submitted 
choice use forms.cleaned_data in views.py.

In my form.py I have 

class AnswerForm(forms.Form):
ANSWER_CHOICES = (
(1, 'Lottery 1'),
(2, 'Lottery 2'),
)
answer = forms.ChoiceField(choices=ANSWER_CHOICES, widget=forms.RadioSelect)
question = forms.IntegerField(widget=forms.HiddenInput)


In problems.html template I have 






Please make a choice between two lotteries.
Which lottery do you want choose   



 
  Two lotteries
   

   
 
   
State 1
   State 2
   State 3
 

 
Lottery 1
{{ problem.0 }}{{ sltlottery }}
 {{ problem.1 }} 
 {{ problem.2 }}
 

   
Lottery 2
 {{ problem.3 }} 
  {{ problem.4 }} 
  {{ problem.5 }} 
 

  

   




{% csrf_token %}
{{ form.as_p }}




It looks like i need a logic statement like the following :  if selected 
choice =1, colour 1= "yellow", colour 2= "white"  else: colour 2= "yellow", 
colour 1= "white"

There are two crucial steps I am not sure how to do.

First, after an user select on choice by click the Radio button, how can I 
track the associated value?  For example, when Lottery 1 is selected, I 
need selected choice =1.
Second, what is the easiest way to set write the logic statement in html? I 
am even not quite sure where to put the logic statement...

Any help would be much appreciated!

Xueqi

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3bca5139-ff0c-4124-a937-947b33bd2c4c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


choice tasks web application

2018-03-12 Thread xueqi dong


Hello, I have just finished the django tutorial here 
https://docs.djangoproject.com/en/2.0/intro/tutorial01/. But I am still not 
sure to write the following intended web application.

The application asks an user to enter his/her name, then to make 30 
choices(either choose 1 or 2). At the end I need to record those 30 choices 
under the user's name.

The major part I am confusing is about data export and import. The tutorial 
shows how to enter the questions in a shell. But I would like to the 
program to read parameters from a matlab matrix(say 30*6 matrix), or 
whatever files possible. Here the number of rows is equal to 30, which is 
equal to the number of task.

Essentially I only need one form. The form should iteratively read one row 
from the matrix and uses the numbers in that row to show a choice task to 
the user. The user makes a choice and proceeds to next form. The next form 
will read the next row from the matrix and shows a new choice task. An 
example of one choice task would look like the following:

Which one do you prefer?

Choice 1: [40,20,10]

Choice 2: [30,50,20]

I am also not sure about using database. The exported data is simply 30 
 numbers of either 1 or 2. Can I just find some way to save this dataset, 
named as the user's name? 

Can anyone help me with this or  let me know where to find an example/ 
tutorial?

Many thanks!

Cheers,

Xueqi

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/aca4f4c8-d935-4c82-8349-b86dfe7f17e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.