4 Replies - 1800 Views - Last Post: 25 June 2012 - 01:48 AM

#1 notice88   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 92
  • Joined: 21-December 11

In $.ajax({}); i want to submit a form or prevent it from submiss

Posted 24 June 2012 - 07:50 AM

in this code. i am performing a check if the value is already existing in the database. if the value is existing, i want to the form to submit, and if not, i want to prevent it from submission by using return false. but its not working. can u tell me whats wrong? And also, is there any way i can take out the 'msg'
variable outside the $.ajax({});? i tried return msg; after the condition and tried alerting it in the onsubmitCheckControlNumber() function but still not working.

<script type ='text/javascript'>
     function onsubmitCheckControlNumber(){
		
		var username = $("#ControlNumber").val();
		
		$.ajax({
				type: "POST",  
				url: "php/CheckControlNumber.php",  
				data: "username="+ username,  
				success: function(msg){  
					
					if(msg == 1)
					{
						$("form#FormUpload").submit();
					}else
					{
						return false;
					}
				return msg;
			}//END success: function(msg){		
		});//END of $.ajax({
		
	
		
	}
     
     </script>


This post has been edited by notice88: 24 June 2012 - 07:54 AM


Is This A Good Question/Topic? 0
  • +

Replies To: In $.ajax({}); i want to submit a form or prevent it from submiss

#2 notice88   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 92
  • Joined: 21-December 11

Re: In $.ajax({}); i want to submit a form or prevent it from submiss

Posted 24 June 2012 - 08:41 AM

well what i did was i disabled the submit button when the control number already exist in the database and enable it if not.. but for further reference. can you answer it? thanks.. im new to javascript

This post has been edited by Dormilich: 24 June 2012 - 11:56 AM
Reason for edit:: removed self-quote

Was This Post Helpful? 0
  • +
  • -

#3 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4303
  • View blog
  • Posts: 13,677
  • Joined: 08-June 10

Re: In $.ajax({}); i want to submit a form or prevent it from submiss

Posted 24 June 2012 - 11:59 AM

the problem is that this is not HTML inline event handling. returning something (esp. from an asynchronous call) from a callback function does not have any effect.
Was This Post Helpful? 0
  • +
  • -

#4 notice88   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 92
  • Joined: 21-December 11

Re: In $.ajax({}); i want to submit a form or prevent it from submiss

Posted 25 June 2012 - 01:42 AM

is there anything thats need to be added?
Was This Post Helpful? 0
  • +
  • -

#5 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4303
  • View blog
  • Posts: 13,677
  • Joined: 08-June 10

Re: In $.ajax({}); i want to submit a form or prevent it from submiss

Posted 25 June 2012 - 01:48 AM

it’s a totally different concept. there is nothing to be added, there is the programme logic to be changed.

if onsubmitChangeNumber() is tied to the submit button, you have to cancel the submit button’s action. you either do that by making it a click button or by killing the submit button’s default action (submitting the form) either via return false in the inline handler or by calling the Event’s preventDefault() method.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1