473,407 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

AJAX opens form (each radio diplays one by one in popup) & close btn saves data

I have form in nette framework where the form works wel. When I added AJAX it stopped to work propely and then I added functionality to "close" button that the answers will be saved after each other. The form is styled that each questions appears on popup seperatly. The js code problems:

Answers aren't saving values in the database after pushing "close" button.

The Ajax should close the form once it is submitter but right now it opens a form istead.


Expand|Select|Wrap|Line Numbers
  1. <!-- LATTE template in Nette -->
  2.  
  3.  
  4. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  5.  
  6.  
  7.  
  8.   <a href="#netPromoterScoreModel" id="open-button" class="btn btn-pink btn-lg btn-block" data-toggle="modal">Dotaznik</a>
  9.  
  10.  
  11.     {form netPromoterScore class => 'ajax-form'}
  12.  
  13.      <!-- FORM START -->
  14.     <div id="netPromoterScoreModel" class="modal fade nps" role="dialog">
  15.       <div class="modal-dialog modal-lg">
  16.  
  17.                 <!-- Modal content-->
  18.                 <div class="modal-content">
  19.  
  20.           <div class="modal-header">
  21.             <h5 class="modal-title">Dotaznik</h5>
  22.             <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  23.               <span aria-hidden="true">×</span>
  24.             </button>
  25.           </div>
  26.  
  27.           <!-- QUESTION 1 -->
  28.           <div id="question0" class="modal-body">
  29.                       <div class="row">
  30.               <div class="col-12 form-group">
  31.                 {label recommendation}
  32.               </div>
  33.               <div id="radios" class="col-12 form-group">
  34.                 {input recommendation}
  35.               </div>  
  36.               <div class="col-12 modal-footer">
  37.                 <a href="javascript:void(0)" class="btn btn-pink" onclick="goNext(0)">Next Question</a>
  38.                 <button id="submit" type="submit" value="submit" class="btn btn-secondary">Close</button>
  39.               </div>
  40.             </div>
  41.                   </div>
  42.  
  43.  
  44.           <!-- QUESTION 2 -->
  45.           <div id="question1" class="modal-body" hidden>
  46.                       <div class="row">
  47.               <div class="col-12 form-group">
  48.                 {label website}
  49.               </div>
  50.               <div id="radios" class="col-12 form-group">
  51.                 {input website}
  52.               </div>
  53.               <div class="col-12 modal-footer">
  54.                 <a href="javascript:void(1)" class="btn btn-pink" onclick="goNext(1)">Next Question</a>
  55.                 <button id="submit" type="submit" value="submit" class="btn btn-secondary">Close</button>
  56.               </div>
  57.             </div>
  58.                   </div>
  59.  
  60.           <!-- QUESTION 3 -->
  61.           <div id="question3" class="modal-body" hidden>
  62.                       <div class="row">
  63.               <div class="col-12 form-group">
  64.                 {label feedback}
  65.               </div>
  66.               <div id="textInput" class="col-12 form-group">
  67.                 {input feedback}
  68.               </div>
  69.               <div class="col-12 modal-footer">
  70.                 <button type="submit" class="btn btn-pink">Submit</button>
  71.               </div>
  72.             </div>
  73.                   </div>
  74.  
  75.  
  76.         </div> <!-- END of modal content-->
  77.  
  78.             </div> <!-- end of Modal dialog-->
  79.         </div> <!--end of the form-->
  80.  
  81.     {/form}
  82.  
  83. </div>
  84.  
  85. <script type="text/javascript">
  86. // jQuery
  87. //next question
  88. function goNext(i) {
  89.     $('#question'+i).attr('hidden', true);
  90.     $('#question'+(i+1)).attr('hidden', false);
  91. }
  92.  
  93. // for submit after each question 
  94. $(document).ready(function(){ 
  95.     $('#submit').click(function(){ 
  96.         ('input[type="radio"]').click(function(){
  97.             // variables for inputs
  98.             var recommendation = $('#recommendation').val();  
  99.             if(input[name="recommendation"]:checked) { 
  100.             $('#return').html('<h4 style="color:red;">Required All Fields..</h4>'); 
  101.             } 
  102.             else { 
  103.             // ajax in nette
  104.             $.nette.ajax({
  105.             method: 'GET',
  106.             url: url
  107.             data:$('#insert_data').serialize(), 
  108.             success:function(data){ 
  109.             $('form').trigger("reset"); 
  110.             $('#return').fadeIn().html(data); 
  111.             setTimeout(function(){ 
  112.             $('#return').fadeOut("slow"); 
  113.             }, 6000); 
  114.             } 
  115.             }); 
  116.             } 
  117.         }
  118.     }); 
  119. }); 
  120. </script>
May 6 '19 #1
1 915
gits
5,390 Expert Mod 4TB
to be honest digging through such code which obviously is somehow a template in whatever 'framework' is somehow a pain - since probably only few people know about that framework. what i can see for example is that something like:

Expand|Select|Wrap|Line Numbers
  1. if(input[name="recommendation"]:checked) {
will trigger a syntax error - unless that 'framework' will have a transpile step before the page is delivered to the client and fixes that syntax during such a step.

your best bet is to just open the developer tools of the browser you are using and checking whats going on - which means javascript errors, what values are transferred with the requests and so on. then you can eliminate all the obvious errors first and then you might have a question that you can ask more specific and probably with a more specific part of some code.

PS: another problem is probably here:

Expand|Select|Wrap|Line Numbers
  1. $('#submit').click(function(){ 
  2.         ('input[type="radio"]').click(function(){
  3.  
which basically would assign a click handler to a node, which in this case i think is not correctly retrieved, when the click handler of the submit element would be executed (aka be clicked).
May 10 '19 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Jens Peter Hansen | last post by:
Hi From my main window I open a series of popup (one close - next opens) in a mockup for a registration proces. From the last popup, I want to click a buttom, so the popup closes and the URL in...
1
by: Jennyfer J Barco | last post by:
Hello I have a datagrid and a linkbuttom in the datagrid that says Picture, every time I click on the link "Picture" my program opens a popup window showing a picture of the item the selected and...
1
by: Matt Jensen | last post by:
Howdy I've got a ASP.NET webform page that pops up a window for a user to make a selection. Once they make a selection in this popup window, the form in the popup is submitted an update to the...
2
by: Doug | last post by:
Is there a way to get the VB code that opens a popup to wait until the popup is closed before continuing?
12
by: colt28 | last post by:
Ok so I found an ajax contact form script but i can't get the b****** to work. I made a bunch of alterations to it and it didn't work so i replaced everything with the original and it still didn't...
11
by: Twayne | last post by:
Hi, Newbie to PHP here, no C or other relevant background, so pretty niave w/r to the nuances etc. but I think this is pretty basic. XP Pro, SP2+, PHP 4.4.7, XAMPP Local Apache Server...
3
by: perhapscwk | last post by:
how to check if a popup is close? thanks.
3
by: falonso | last post by:
How can I do build a multiple-choice exam using a form with radio buttons. question No. 1 Answers: yes: value=2 maybe: value=1 No: value=0 question No. 2 Answers: yes: value=2 maybe:...
0
by: guru n | last post by:
hi all.. i have a application were in have a textfeild say X.. to input data in X i need to click select button.. a popup window appears.. bu default all data present in database is displayed.. i...
10
by: AirDavidADP | last post by:
I have a query that runs each week that shows data from the current week out 26 weeks. So this week it would have weekend dates from 1/13 to 7/21. Next week the columns will start at 1/20 – 7/28. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.