On Monday, November 20, 2017 at 8:50:51 PM UTC-8, Maurice Waka wrote: > > HI this is my code: >
Do you really have a lot of stuff *outside* of the <html></html> tags? Or are you showing us several separate files? I'm not sure how to tie this all together. /dps > {{for q in quizes:}} > {{quiz = q.message}} > {{pass}} > > <html> > <body> > <div id="header">Chat Bot</div> > <div id="messages"> > <a href='https://code.sololearn.com/Wm2n17OoSTDk/?ref=app > '>Original</a> > </div> > <form id='user' onsubmit="return false;"> > <input type="text" id="msgbox" name='message' > placeholder="Type a message..." /> > <button id="send" > onclick="ajax('{{=URL('view_searches')}}',['message'],'target');" > >SEND</button> > </form> > </body> > </html> > > <style> > * { > margin: 0px; > user-select: none; > -webkit-user-select: none; > -moz-user-select: none; > } > body { > margin: 0px; > height:400px; > bottom:0; > } > #user { > width: 100vw; > position: fixed; > left: 0px; > bottom: 0px; > display: block; > background-color: #EEE; > white-space: nowrap; > height:105px; > } > #msgbox { > width: calc(80% - 12px); > min-height: 25px; > max-height: 35px; > padding: 5px; > outline: none; > border: solid 1px #AAA; > display: inline-block; > vertical-align: center; > float: left; > background-color: #FFF; > border-radius: 25px; > resize: none; > margin: 0px; > word-wrap:break-all; > } > #send { > width: 20vw; > height: 35px; > display: inline-block > outline: none; > border: none; > color: #FFF; > background-color: #00F; > float: left; > border-radius: 25px; > padding: 0px; > cursor: pointer; > margin: 0px; > } > #send:active { > background-color: #00A; > outline: none; > } > #header { > display: flex; > justify-content: left; > align-items: center; > width: calc(100% - 30px); > height: 20px; > padding: 15px; > color: #FFF; > font-size: 200%; > font-weight: bolder; > background-color: #00F; > position: fixed; > font-family: arial; > } > #messages { > display: block; > width: 100vw; > height: calc(100% - 87px); > background-color: #EEE; > position: fixed; > top: 50px; > left: 0px; > overflow: auto; > overflow-x: hidden; > overflow-y: auto; > } > .left { > text-align: left; > /* > display: block; > */ > } > .right { > text-align: right; > /* > display: block; > */ > } > .incoming { > background-color: #FFF; > color: #000; > border: solid 1px #AAA; > } > .outgoing { > background-color: #00F; > color: #FFF; > } > .section { > display: block; > width: calc(100% - 30px); > padding-left: 15px; > padding-right: 15px; > margin-top: 7.5px; > margin-bottom: 7.5px; > } > .message { > display: inline-flex; > justify-content: left; > align-items: center; > border-radius: 25px; > padding: 10px; > font-size: 10pt; > } > input:first { > color: #F00; > } > .incoming:active { > background-color: #EEE; > } > .outgoing:active { > background-color: #00A; > } > * { > outline: none; > tap-highlight: none; > -webkit-tap-highlight: none; > -webkit-tap-highlight-color: none; > -moz-tap-highlight: none; > -moz-tap-highlight-color: none; > -khtml-tap-highlight: none; > -khtml-tap-highlight-color: none; > } > a { > display: block; > text-align: center; > } > </style> > > > <script> > $(function(){ > var commands = { > "random":"var rand = (Math.floor(Math.random() * 10)); > incoming(rand);", > "commands":"var objstr = JSON.stringify(commands); objstr = > JSON.stringify(commands, null, 4); incoming(objstr)" > } > var responseSys = { > "hi":"Hello There!", > "bye":"GoodBye!" > }; > function cmd(name, action){ > commands[name] = action; > } > function outgoing(text){ > var newMsg = "<div class='section right'><div class='message > outgoing'>" + text + "</div></div>"; > $("#messages").append(newMsg); > } > function incoming(text){ > var newMsg = "<div class='section left'><div class='message > incoming'>" + text + "</div></div>"; > $("#messages").append(newMsg); > window.scrollTo(0, parseInt($("#messages").innerHeight)) > } > $("#send").click(function(){ > $("#msgbox").trigger("blur") > var text = $("#msgbox").val(); > if(text != null && text != ""){ > $("#msgbox").val(""); > text = text.replace(/</ig, "<"); > text = text.replace(/>/ig, ">"); > text = text.replace(/\n/ig, "<br />"); > outgoing(text); > reply(text) > } > else{ > // Praise the Sun > incoming("Please, don't send empty messages.") > } > }); > $("#msgbox").keyup(function(e){ > if(e.which == 13){ > $("#send").trigger("click") > } > else{ > // Do Nothing > } > }); > > incoming("Hello!<br />This is a small ChatBot made by Andrew > Grider. Feel Free to implement any commands or functions but please don't > change this message! If you do add to the code however, then feel free to > add your name to the contributors message!"); > incoming("Add responses using this JavaScript function, > responses(your_message, my_reply) and add commands using this function, > cmd(command_name, command_action)"); > incoming("Contributors:<br />Maz<br />The Coding Sloth") > function responses(msg, response){ > msg = msg.toLowerCase(); > responseSys[msg] = response; > } > function reply(txt){ > txt = txt.toLowerCase(); > if(txt[0] == "r" && txt[1] == "e" && txt[2] == "s" && txt[3] == > "p" && txt[4] == "o" && txt[5] == "n" && txt[6] == "s" && txt[7] == "e" && > txt[8] == "s" && txt[9] == "("){ > try{ > eval(txt); > } > catch(e){ > incoming(e); > } > } > else if(responseSys[txt] != undefined && responseSys[txt] != > null && responseSys[txt] != "" ){ > incoming(responseSys[txt]); > > } > else if(commands[txt] != null && commands[txt] != undefined && > commands[txt] != ""){ > try{ > try{ > eval(commands[txt]) > } > catch(e){ > incoming("Error Executing") > } > } > catch(e){ > incoming("Command not defined") > } > } > else if(txt[0] == "c" && txt[1] == "m" && txt[2] == "d"){ > try{ > eval(txt) > } > catch(e){ > incoming(e) ; > } > } > else setTimeout(function () { > return incoming('Just a sec...'); > }, 3000); > return setTimeout(function () { > return incoming('{{=quiz}}'); > }, 4000); > } > responses("example", "My Response") > responses("hello", "Hello World.. or.. person.") > }); > </script> > > > On Tue, Nov 21, 2017 at 7:15 AM, Dave S <snide...@gmail.com <javascript:>> > wrote: > >> >> >> On Monday, November 20, 2017 at 7:41:55 PM UTC-8, Maurice Waka wrote: >>> >>> In my previous question: [web2py] How to get the last DB Field data : >>> I got some good response. But my issue still persists. >>> My code: >>> >>> >>> <https://lh3.googleusercontent.com/-ITVP6pmYGH0/WhOeE6ZRvTI/AAAAAAAANOE/htmOlcxFLQ8xNnjFj7v00JG4tmv4ZoWVQCLcBGAs/s1600/Screenshot%2Bfrom%2B2017-11-21%2B06-25-18.png> >>> def view_searches(): >>> quizy = [] >>> form = SQLFORM(db.post).process() >>> if request.vars.message: >>> db.post.insert(message = request.vars.message) >>> quizes = db(db.post.author == auth.user.id).select(db.post.ALL, >>> orderby=~db.post.created_on, limitby=(0,1)) >>> for q in quizes: >>> quizy.append(q.message) >>> quiz= quizy[0] >>> print quiz >>> return dict(form=form, quiz=quiz) >>> >>> Note the print quiz for illustration purpose. >>> Now note the print screen below: >>> >>> >>> <https://lh3.googleusercontent.com/-ITVP6pmYGH0/WhOeE6ZRvTI/AAAAAAAANOE/htmOlcxFLQ8xNnjFj7v00JG4tmv4ZoWVQCLcBGAs/s1600/Screenshot%2Bfrom%2B2017-11-21%2B06-25-18.png> >>> >>> >>> Notice the last post is;'God is love' >>> >>> >>> - If using print, i get the exact last posted item >>> - if I use return on the html page, I get aowirhsgporhj......previous >>> posted message, also shown on the terminal. >>> - Note that the html page returns the random letter print; >>> aowirhsgporhj... >>> instead of 'God is love' >>> - I used print to illustrate the erros. If i remove print function, >>> the error persists where i can't get the last posted item >>> >>> My request is how do i resolve this? >>> Regards >>> >> >> >> Perhaps you should have gotten a clean console screen before the run that >> you wanted to include in the post :-) >> It's a little bit hard to see the relevant part of the screen. >> >> Also, did you ever show us the view template code you are using? >> >> Now, commenting on your code above, I would expect quizy[0] to be the >> only element in quizy, due to your limitby=(0,1). I am not yet seeing >> why your page isn't showing the right result yet. I suspect something in >> your view, which is why I asked about the template code. But what is the >> blue bubble above the Send button? It says "God is love" ... are you >> putting the result in the wrong place? >> >> /dps >> >> -- >> Resources: >> - http://web2py.com >> - http://web2py.com/book (Documentation) >> - http://github.com/web2py/web2py (Source code) >> - https://code.google.com/p/web2py/issues/list (Report Issues) >> --- >> You received this message because you are subscribed to a topic in the >> Google Groups "web2py-users" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/web2py/dN9KfQULX54/unsubscribe. >> To unsubscribe from this group and all its topics, send an email to >> web2py+un...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.