Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts

    Question small Jquery form submittal/reset issue

    I'm including a portion of the code I use on form submittal. I have 2 radio buttons and a user must select one of these options or the form will not submit ( see green code) . I wrote a check to ensure that at least one radio is checked off or they get an error and it hightlights the radio boxes. This works fine , the first time. Once the submittal passes the checks I have put in it, the data is submitted via ajax and this resets most of the form , including unchecking the radio boxes ( shown in red) . The problem is that if a user wants to then submit another request via the form , even when they check off a radio box, it is not passing the "if not checked" code

    Code:
    if ( $("#scheduling_1").attr('checked') == false && $("#scheduling_0").attr('checked') == false ){
        	$("#scheduling_1,#scheduling_0").addClass('inputBG-error');
    	data1++  
      }
      
      if(data1 > 0 ){
    	$("#control").removeClass('inputBG-error');
                msg1.append("<div class='blk-border'><p class='red'>You have left some information blank.</p><p> Please fill out any fields highlighted in red and try again.</p></div>");
    	  }
    
    if(data1 > 0 ){
    $("#submit-response").html(msg1).delay(250).show("slow");
    return false
    	  }
    
    		//Form submittal to server via Jquery .Ajax call begins here
    	var datastring = $('#rzrequestform').serialize();
        $.ajax({
            type: "POST",
            url: "/Subwebs/Information Services/HelpDesk/rz/rzredzoneprocessUser.asp",
            data: datastring,
            success: function(html){
    		var tt=  $(html).find("#hidden").text();
    			var msg = $("<div id='request-reply'></div>"); 
    			if ( $('#ticket').is(':checked')) {
    			  msg.html("<div class='blk-border'><p>Your RedZone request has been submitted to the HelpDesk.</p><p class=\"red\"><strong>Your Redzone ID # is: "+tt+"</strong></p><p>You should save this number in case you would like to request any changes or updates to the notice you have requested.</p><p><a href='/Subwebs/Information Services/HelpDesk/scticket.asp'>Click here to open a web ticket also.</a></p></div>");			  
    			}
    			else {
    			msg.html("<div class='blk-border'><p>Your RedZone request has been submitted to the HelpDesk.</p><p class=\"red\"><strong>Your Redzone ID # is: "+tt+"</strong></p><p>You should save this number in case you would like to request any changes or updates to the notice you have requested.</p></div>");						
    			}
    			
    		   $('input,textarea,#legend').removeClass('inputBG-error')
    		   $(':input','#rzrequestform').not(":button, :submit, :reset, :hidden,[name='requestername'],[name='requesterusername']").val("")
    		  $('#scheduling_1,#scheduling_0').removeAttr('checked');	
    		   
    		   $("#submit-response").html(msg).delay(250).show("slow");
    			},

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    nevermind I fixed it. I was inadvertantly clearing the values of the radio boxes in my form reset function. I had to change this:


    Code:
    $(':input','#rzrequestform').not(":button, :submit, :reset, :hidden,[name='requestername'],[name='requesterusername']").val("")
    		  $('#scheduling_1,#scheduling_0').removeAttr('checked');
    to this:

    Code:
    $(':input','#rzrequestform').not(":button, :submit, :reset, :hidden,[name='requestername'],[name='requesterusername'],[name='scheduling']").val("")
    		  $('#scheduling_1,#scheduling_0').removeAttr('checked');


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •