Cant get into function

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 1485 Views - Last Post: 07 June 2012 - 03:00 PM

#1 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 565
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Cant get into function

Posted 06 June 2012 - 11:07 AM

I have managed to do a bit of error detection, and I have found that my form dont display because I cant get into my function. In the head of my document, I have
<script type="text/javascript" src="http://www.test</script>


This calls up this
alert("Entered File");

// on ready, load enquiry form div
$(document).ready(function () {
	enquiryform_load();
	alert("Entered ready");
});



Now the first alert goes off, but the one in the function doesnt, so that tells me it is never getting into it. Is there any reason why this may be the case?

Cheers

Nick

This post has been edited by nick2price: 25 June 2012 - 09:23 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Cant get into function

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4136
  • View blog
  • Posts: 13,056
  • Joined: 08-June 10

Re: Cant get into function

Posted 06 June 2012 - 11:17 AM

enquiryform_load() may not be defined Ö
Was This Post Helpful? 0
  • +
  • -

#3 exiles.prx  Icon User is offline

  • D.I.C Head

Reputation: 65
  • View blog
  • Posts: 241
  • Joined: 22-November 10

Re: Cant get into function

Posted 06 June 2012 - 11:19 AM

You could also have an error in your enquiryform_load function which is causing the java script to break/end before the second alert executes.
Was This Post Helpful? 0
  • +
  • -

#4 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 565
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: Cant get into function

Posted 06 June 2012 - 11:26 AM

Sorry, I didnt post that function as I didnt think it would be causing the issue.
// load enquiry form ajax content
function enquiryform_load(){
    	$('#enquiry_form').load('http://www.test');
	alert("Entered Load");
}


The above function then loads a php file with ajax in it. Without showing all the code of the file being called, the basic part connects to the database, and loads the form. The problem is, I cant get the form to display. Thats why I put alerts in the javascript file to see if they go off, which they dont. I dont know if I can place anything in there that will definately go off if entered?

Nick

This post has been edited by nick2price: 25 June 2012 - 09:23 AM

Was This Post Helpful? 0
  • +
  • -

#5 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4136
  • View blog
  • Posts: 13,056
  • Joined: 08-June 10

Re: Cant get into function

Posted 06 June 2012 - 11:30 AM

are you sure the JSONP call is correct there? IIRC .load() can directly load the response in the concerned element.
Was This Post Helpful? 0
  • +
  • -

#6 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 565
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: Cant get into function

Posted 06 June 2012 - 11:56 AM

Well, if I type the proper url into the browser (changed it a bit for the post), I get the form
http://www.test.com


So that seems to be correct. So the problem must be related to them javascript functions, because they never seem to be called.

This post has been edited by nick2price: 25 June 2012 - 09:21 AM

Was This Post Helpful? 0
  • +
  • -

#7 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4136
  • View blog
  • Posts: 13,056
  • Joined: 08-June 10

Re: Cant get into function

Posted 06 June 2012 - 12:06 PM

but your function is a recursive call (you call a function, that calls in JSONP itself, Ö)
Was This Post Helpful? 1
  • +
  • -

#8 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 565
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: Cant get into function

Posted 06 June 2012 - 12:15 PM

To be honest, I dont really know whats going on as I dont really work with these languages (although I am trying hard to learn). My company has a website, and on that website is a contact form. I got asked to create a new website which I have done. My last job is to get the contact form from the old website into the new website. All I have done is copy the code, so I dont know why it wouldnt work on the new site.
Its probably best to take you through the whole process. So the header calls the javascript file. In the main body, I do something slightly different, like so
<?php
	// enquiry form include space
	include("inc/enquiryform_include.php");
?>


Now that loads a completely different form altogether, one for users with javascript disabled. The main part of that file is
<div id="enquiry_form">
	<script type="text/javascript">
	document.write('<img src="/graphics/loading.gif" alt="Loading..."/> Please Wait...')
	</script>
	<noscript>
		<?php
			// non JS based form processor
			if($_POST['nonjsform']=="true"){

So, if there is no script, load that form. If there is javascript enabled, I presume that document.write at the top of the file above will load it.

At this moment in time, if I disable javascript, I get the non javascript form displayed. If javascript is enabled, I get Loading... Please Wait.... (so whats in the document.write). So I think the issue may relate to the above document.write never finishing, therefore the javascripts $(document).ready(function () never gets entered.

Thats all guess work though, as I say, I am not to sure whats going on, lol.
Was This Post Helpful? 0
  • +
  • -

#9 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4136
  • View blog
  • Posts: 13,056
  • Joined: 08-June 10

Re: Cant get into function

Posted 06 June 2012 - 12:23 PM

View Postnick2price, on 06 June 2012 - 09:15 PM, said:

At this moment in time, if I disable javascript, I get the non javascript form displayed. If javascript is enabled, I get Loading... Please Wait.... (so whats in the document.write). So I think the issue may relate to the above document.write never finishing, therefore the javascripts $(document).ready(function () never gets entered.

once you have printed that, document.write() has finished. the message "Please wait ..." has nothing to do with the load status, itís just some text.
Was This Post Helpful? 0
  • +
  • -

#10 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 565
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: Cant get into function

Posted 06 June 2012 - 12:29 PM

Quick question. I am trying to figure out how it knows the load the javascript version in the div for the non javascript version. Is this
$('#enquiry_form').load('http://www.test');


#enquiry_form, relating to the div name?
<div id="enquiry_form">
	<script type="text/javascript">
	document.write('<img src="/graphics/loading.gif" alt="Loading..."/> Please Wait...')
	</script>

This post has been edited by nick2price: 25 June 2012 - 09:21 AM

Was This Post Helpful? 0
  • +
  • -

#11 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4136
  • View blog
  • Posts: 13,056
  • Joined: 08-June 10

Re: Cant get into function

Posted 06 June 2012 - 12:32 PM

$('#enquiry_form').load(some_URI); will load the content of some_URI into the element with the ID of enquiry_form.
Was This Post Helpful? 1
  • +
  • -

#12 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 565
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: Cant get into function

Posted 06 June 2012 - 12:36 PM

Wow, to confusing. So I include the file which has the div enquiry_form. The javascript file is loaded in the head, and the browser definately goes into this. I have changed the javascript file for now to be
alert("Entered File");
$('#enquiry_form').load('http://www.example.com');


When I load the webpage, the alert goes off, but the form does not load. However, if I take that url in the load call and enter it directly into the browser, it loads the form.

Slightly confused now where to go from here, lol.

This post has been edited by Dormilich: 11 September 2012 - 05:05 AM

Was This Post Helpful? 0
  • +
  • -

#13 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4136
  • View blog
  • Posts: 13,056
  • Joined: 08-June 10

Re: Cant get into function

Posted 06 June 2012 - 02:10 PM

can you uncomment that function in your page, so I can check the AJAX call?
Was This Post Helpful? 1
  • +
  • -

#14 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 879
  • View blog
  • Posts: 1,893
  • Joined: 30-January 09

Re: Cant get into function

Posted 06 June 2012 - 02:17 PM

You've rewritten the website? I'm going to hazard a guess that you're not including the jQuery library, so references to anything like $('...') is going to fall flat on it's arse because it doesn't understand the syntax.

Have a look in the <head> section of your HTML and see if there's something like this:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>

If the reference to jQuery is missing, there's your problem.
Was This Post Helpful? 1
  • +
  • -

#15 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 565
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: Cant get into function

Posted 06 June 2012 - 03:01 PM

I have rewritten the website no problems. But I am transfering the code for the form over from the old website as it has a lot of functionality I need. Its only the form thats causing the issue. I do have the jquery references in my header.

I have a few easy things to do in regards to the website. I am going to leave the form for now and come back to it when I am fresh. I really appreciate your help and I am sure I will be calling on you again soon :helpsmilie:
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2