Jump to content

Recommended Posts

Hey guys, I have a function i made that keeps giving me the error in firebug saying "edit_post is not defined"

after a few hours i just gave up and wraped a php function around it to call it. But still this has baffled me as in why.

when i do view source on the page its all correct. All the variables are filled in correctly. Even if i have the code on the same page. Also keep in mind the code works fine with out the function or with wraping a php function around it.

 

this function only uses two variables. Maybe i can't wrap a java script function with jquery Ajax in it or something?

either way it saying the function is undefine first makes me think it cant read the function.

 

 

edit_post(<?php echo $t; ?>, <?php echo $id; ?>);


function edit_post(t,id) { ?>

$(function(){ 
$("#edit_thread<?php echo $t; ?>").hide();
$("#save<?php echo $t; ?>").hide();
$("#cancel<?php echo $t; ?>").hide();

				/*/ edit button  /*/
		$("#edit_button<?php echo $t; ?>").click(function(event){	
				event.preventDefault();	

		$("textarea#edit_thread1").hide();
		$("textarea#edit_thread2").hide();
		$("textarea#edit_thread3").hide();
		$("textarea#edit_thread4").hide();
		$("textarea#edit_thread5").hide();
		$("textarea#edit_thread6").hide();
		$("textarea#edit_thread7").hide();
		$("textarea#edit_thread8").hide();
		$("textarea#edit_thread9").hide();
		$("textarea#edit_thread10").hide();

		$("#save1").hide();
		$("#save2").hide();
		$("#save3").hide();
		$("#save4").hide();
		$("#save5").hide();
		$("#save6").hide();
		$("#save7").hide();
		$("#save8").hide();
		$("#save9").hide();
		$("#save10").hide();

		$("#cancel1").hide();
		$("#cancel2").hide();
		$("#cancel3").hide();
		$("#cancel4").hide();
		$("#cancel5").hide();
		$("#cancel6").hide();
		$("#cancel7").hide();
		$("#cancel8").hide();
		$("#cancel9").hide();
		$("#cancel10").hide();	

		$("#thread1").show();
		$("#thread2").show();
		$("#thread3").show();
		$("#thread4").show();
		$("#thread5").show();
		$("#thread6").show();
		$("#thread7").show();
		$("#thread8").show();
		$("#thread9").show();
		$("#thread10").show();


		$("#edit_button1").show();
		$("#edit_button2").show();
		$("#edit_button3").show();
		$("#edit_button4").show();
		$("#edit_button5").show();
		$("#edit_button6").show();
		$("#edit_button7").show();
		$("#edit_button8").show();
		$("#edit_button9").show();
		$("#edit_button10").show();

				$("#thread<?php echo $t; ?>").hide();

				$("#edit_button<?php echo $t; ?>").hide();
				$("#save<?php echo $t; ?>").show("slow");
				$("#cancel<?php echo $t; ?>").show("slow");

				$("#edit_thread<?php echo $t; ?>").show("slow");
		});	


				/*/ cancel button  /*/
		$("#cancel<?php echo $t; ?>").click(function(event){	
				event.preventDefault();	

				$("#cancel<?php echo $t; ?>").hide();
				$("#save<?php echo $t; ?>").hide();
				$("#edit_thread<?php echo $t; ?>").hide();
				$("#edit_button<?php echo $t; ?>").show("slow");

				$("#thread<?php echo $t; ?>").show("slow");
		});



			/*/ save button  /*/
		$("#save<?php echo $t; ?>").click(function(event){	
				event.preventDefault();	
		$.ajax({
				url: "/System_Lords/ajax/forum_edit.php",            

				type: 'POST',            

				dataType: 'json',            

				data: { 

					edit_thread: $('#edit_thread<?php echo $t; ?>').val(),
					id: '<?php echo $id; ?>'

				},            

				success: function(response) {              

				$('#thread<?php echo $t; ?>').html(response.thread);


				}        

				});

		$("#thread<?php echo $t; ?>").hide();			
fade_message("#post_success<?php echo $t; ?>" , "Post Successfully Updated" , 1000 , 1500);


		$("#cancel<?php echo $t; ?>").hide();
		$("#save<?php echo $t; ?>").hide();
		$("#edit_thread<?php echo $t; ?>").hide();
		$("#edit_button<?php echo $t; ?>").show("slow");

		$("#thread<?php echo $t; ?>").delay(2490).show("slow");


		});



});

} // edit_post bracket

Link to comment
https://forums.phpfreaks.com/topic/260715-strange-java-script-function-error/
Share on other sites

That doesn't matter in JavaScript (or PHP for that matter) as the code is parsed before it's executed.

 

Will work:

<script>
hello();
function hello() {
    alert('Hello, World!');
}
</script>

 

Will work:

<?php
hello();                                                                                                                                                                                                         
function hello() {
    echo 'Hello, World!';
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.