在电梯中获取复选框和单选按钮值 [英] get checkbox and radio button value in lift

查看:120
本文介绍了在电梯中获取复选框和单选按钮值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试在电梯框架中处理表单。我的表单有一个复选框和单选按钮。如何检查复选框是否被选中和所选的单选按钮。下面的代码我用来获取其他元素的值。

i am trying to processing a form in lift frame work. my form is having one checkbox and radiobuttons. how could i check whether the checkbox is checked or not and the selected radio button.the following code i used to get other elements value.

视图:

<form class="lift:MySnippet?form=post">
 From:<input type="text" name="source" /><br />
 To:  <input type="text" name="destination" /><br />
 Age: <input type="text" name = "age"/><br />
 Return: <input type="checkbox" name="needreturn" value="Return Ticket" /><br />
 <input type="radio" name="sex" value="male" />Male<br />
 <input type="radio" name="sex" value="male" />Female<br />
 <input type="submit" value="Book Ticket"/>
</form>

且MySnippet scala代码为:

and MySnippet scala code is:

  object MySnippet {
     def render = {
             var from = ""
             var to = ""
             var age = 0

            def process() {
                S.notice("in process function")
            }

     "name=source" #> SHtml.onSubmit(from = _) &
     "name=destination" #> SHtml.onSubmit(to = _) &
     "name=age" #> SHtml.onSubmit(s => asInt(s).foreach(age = _)) &
     "type=submit" #> SHtml.onSubmitUnit(process)        
   }
  }

处理复选框和单选按钮。任何人都可以提前帮助我... thanx。

in this how could i process the checkbox and radio button. can anyone help me...thanx in advance.

推荐答案

你需要在HTML中指定选项吗?如果没有,最简单的方法是:

Do you need to specify the choices in your HTML? If not, the easiest way is:

Return: <input type="checkbox" name="needreturn" /><br />
Sex: <input type="radio" name="sex" />

和CSS变形:

val radioChoices = List("male", "female")
var sex:Box[String] = None
var needReturn:Boolean = false

"@sex" #> SHtml.radio(radioChoices, sex, (resp) => sex = Full(resp)) &
"@needreturn" #> SHtml.checkbox(needReturn, (resp) => needReturn = resp)

c $ c> SHtml.radio 与 SHtml.ajaxRadio SHtml.checkbox code> SHtml.ajaxCheckbox 如果您希望您的选择发送到服务器每次更改的值,而不是当表单提交

You could replace SHtml.radio with SHtml.ajaxRadio and SHtml.checkbox with SHtml.ajaxCheckbox if you want your selection to be sent to the server every time the value is changed, instead of when the form is submitted

我相信你也可以使用 SHtml.onSubmit 和上面的复选框和广播一样,但我必须做一些测试究竟如何。

I believe you can also use the SHtml.onSubmit as you do above for the checkbox and radio, but I'd have to do some testing to figure out exactly how.

关于单选按钮,您可以在以下位置找到有关更改标签输出方式的信息: https://groups.google.com/forum/?fromgroups=#!topic/liftweb/rowpmIDbQAE

With regards to the radio button, you can find some information about changing the way the label is output here if you need to: https://groups.google.com/forum/?fromgroups=#!topic/liftweb/rowpmIDbQAE

这篇关于在电梯中获取复选框和单选按钮值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆