How to get the value of radio

26 views
Skip to first unread message

夜帝

unread,
Feb 17, 2012, 9:30:49 AM2/17/12
to chica...@googlegroups.com
   Html code:  
     <form method="post">
       <label><input type="radio" name="sex" value=“0” id="male"/>male</label>
       <label><input type="radio" name="sex" value=“1” id="female"/>female</label>
       <input name="submitBtn" value="submit" type="submit" />
      </form>
   Like this form,How to get the value of the checked radio in controller?

chan sisowath

unread,
Feb 17, 2012, 10:18:12 AM2/17/12
to chica...@googlegroups.com
something like

toto('POST', []) ->
  Sex = Req:post_param("sex"),


2012/2/17 夜帝 <tong...@gmail.com>

夜帝

unread,
Feb 17, 2012, 10:25:55 PM2/17/12
to chica...@googlegroups.com
But I printed this result,It was garbled like follows:
Print:
io:format(Req:post_param("sex"))
Result:
“0â€

2012/2/17 chan sisowath <chan.s...@gmail.com>



--
我踏月色而来!

Graeme Defty

unread,
Feb 17, 2012, 10:33:42 PM2/17/12
to chica...@googlegroups.com

You need io:format/2, not io:format/1.
____________________________________

夜帝

unread,
Feb 17, 2012, 10:57:19 PM2/17/12
to chica...@googlegroups.com
The result was [226,128,156,49,226,128,157] ,But how to get the value of the checked radio?I think the reason is that there are two Radio,and their name is radio。

2012/2/18 Graeme Defty <graeme...@gmail.com>



--
我踏月色而来!

Kai Janson

unread,
Feb 17, 2012, 11:04:55 PM2/17/12
to chica...@googlegroups.com
http://erldocs.com is a fantastic source on the library functions of Erlang.

—Kai

夜帝

unread,
Feb 17, 2012, 11:59:08 PM2/17/12
to chica...@googlegroups.com
Who can give me an example ,I want to get the value of the checked radio,and save into the database.Through   Req:post_param("sex")  to get the results can not save into the database.

2012/2/18 Kai Janson <kot...@gmail.com>

http://erldocs.com is a fantastic source on the library functions of Erlang.

—Kai



--
我踏月色而来!

Marutha

unread,
Feb 18, 2012, 12:10:21 AM2/18/12
to chica...@googlegroups.com

io:format("~s",[ Req:post_param("sex") ]).
TnR
Marutha

Kai Janson

unread,
Feb 18, 2012, 12:22:33 AM2/18/12
to chica...@googlegroups.com
In your view you would have something like this:

    <input type="radio" id="radio1" name="radio1" value="1" />1
    <input type="radio" id="radio1" name="radio1" value="2" />2
    <input type="radio" id="radio1" name="radio1" value="3" />3
    <input type="radio" id="radio1" name="radio1" value="4" />4
    <input type="radio" id="radio1" name="radio1" value="5" />5

And then in your controller you would get the value for radio1 like this:

Choice = Req:post_param("radio1"),
error_logger:info_msg("Choice was [1..5]: ~p~n",[Choice]),

At this point in time you can persist the information.

—Kai

chan sisowath

unread,
Feb 18, 2012, 7:10:50 AM2/18/12
to chica...@googlegroups.com
the problem is from your code i think,

value=“0”  is not equal to value="0"

:)

2012/2/17 夜帝 <tong...@gmail.com>

夜帝

unread,
Feb 18, 2012, 9:15:04 AM2/18/12
to chica...@googlegroups.com
To chan sisowath:
Thank you,but I don't understand you say,can you give me an example?

2012/2/18 chan sisowath <chan.s...@gmail.com>



--
我踏月色而来!

Seven Du

unread,
Feb 18, 2012, 11:25:39 AM2/18/12
to chica...@googlegroups.com
look carefully you can find Chinese version of quotes.

Evan Miller

unread,
Feb 18, 2012, 11:48:04 AM2/18/12
to chica...@googlegroups.com
The quotes should be straight and not curly.

An easy fix would be

value=0

--
Evan Miller
http://www.evanmiller.org/

Message has been deleted

Kai Janson

unread,
Feb 18, 2012, 12:11:14 PM2/18/12
to chica...@googlegroups.com
9527 wrote:
9527 寫: 
<form method="post">
       <label><input type="radio" name="sex" value=“0” id="male"/>male</label>
       <label><input type="radio" name="sex" value=“1” id="female"/>female</label>
       <input name="submitBtn" value="submit" type="submit" />
      </form>


I think, you can rewrite the html codes to:
我想, 你可以改寫 html:
<form method="post">
  <input type="radio" id="sex" name="sex" value="male" />Male
  <input type="radio" id="sex" name="sex" value="female" />Female
  <input name="submitBtn" value="submit" type="submit" />
</form>

Then, in the controller, create the following to capture the radio results:
然後, 在 controller 裡, 新建以下 erlang codes 來獲取你想要結果:

    Choice = Req:post_param("sex"),
    error_logger:info_msg("Choice was: ~p~n",[Choice])


請注意, 不要用 “ ”.  請用 " ".  符號不同, 結果不同.
Please be careful, and do not use “ ”.  Please use " ".  Different symbols, different results.

Hope that helps a little.
Reply all
Reply to author
Forward
0 new messages