ok - thanks -- that makes sense and works. On Feb 26, 2:35 pm, Marius <[email protected]> wrote: > Well it looks like you are submitting a non ajax form. You can easily > use ajax forms. > > something like: > > def calcForm(xhtml:NodeSeq):NodeSeq = { > SHtml.ajaxForm(Helpers.bind("f", xhtml, > "age" -> SHtml.text(ageVar.is.toString, v => ageVar(v.toInt)), > "male" -> SHtml.text(maleVar.is.toString, v => > maleVar(v.toBoolean)), > "submit" -> SHtml.ajaxSubmit("Calculate", () => { > > // return your JSCmd here > }), > "le" -> le.toString > )) > > On 26 feb., 18:58, sdillard <[email protected]> wrote: > > > I am probably confused on what exactly is going on in the request / > > response cycle here, but I am trying to show a table cell after a > > calculation is performed, and I can't seem to get the js to run. The > > JS is being called in the showResults method that is bound to the > > submit action. I am guessing that the submit action is reloading the > > page, so there is no opportunity to run the js. Any suggestions on > > how I should be doing this instead? I am learning lift, and I am > > working on an app that needs to be completely stateless (no db > > backend, no cookies, no session). > > > I have the following for my page: > > > <lift:surround with="default" at="content"> > > <table> > > <tbody> > > <tr> > > <td> > > <lift:mortality.calcForm form="POST" id="mortalityForm"> > > Age: <f:age><input > > type="text"/></f:age><br/> > > Male: <f:male><input > > type="text"/></f:male><br/> > > <f:submit><input type="submit" > > value="calculate"/></f:submit> > > </lift:mortality.calcForm> > > </td> > > <td id="mortalityResult" style="display:none;" > > > <lift:mortality.doCalculate> > > Life Expectancy: <r:le>50</r:le> > > </lift:mortality.doCalculate> > > </td> > > </tr> > > </tbody> > > </table> > > </lift:surround> > > > Then in my snippet code I have the following: > > class Mortality { > > object ageVar extends RequestVar[Int](S.param("age").map(_.toInt) > > openOr 0) > > object maleVar extends RequestVar[Boolean] > > (S.param("male").map(_.toBoolean) openOr false) > > var le = "0" > > def calculateLifeExp = { > > val calcLE = Annuity2000.lifeExpectancy(ageVar.is, maleVar.is) > > le = String.format("%.2f",double2Double(calcLE)) > > } > > def doCalculate(xhtml:NodeSeq):NodeSeq = { > > calculateLifeExp > > Helpers.bind("r", xhtml, > > "le" -> le.toString > > ) > > } > > def showResults():JsCmd = { > > JsCmds.Run("$('#mortalityResult').show();alert('I ran')") > > } > > def calcForm(xhtml:NodeSeq):NodeSeq = { > > Helpers.bind("f", xhtml, > > "age" -> SHtml.text(ageVar.is.toString, v => ageVar(v.toInt)), > > "male" -> SHtml.text(maleVar.is.toString, v => > > maleVar(v.toBoolean)), > > "submit" -> SHtml.submit("Calculate", showResults), > > "le" -> le.toString > > ) > > } > > > } > >
-- You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
