Javascript

Display Div tag with button click

Type in the text

Advertisements

Handy Php scripts

echo "<script>alert('Record Not found');</script>";
echo "<SCRIPT LANGUAGE='javascript'>location.href='inbound.php';</SCRIPT>";
echo "<SCRIPT LANGUAGE='javascript'>location.reload(true);</SCRIPT>";

$sql = "SELECT * FROM `items` WHERE `item_barcode` = '$item_barcode' ";
$result= jms_mysql_query($sql , $db_link);
$no_of_rows=mysql_num_rows($result);

CONFIRM DELETE BOX IN PHP PAGE in ONE LINE

This was really quite hard for me to get this working but today finally I made it. If you are having problem in creating a confirm delete box directly from php page without any extended java script here is the script for you. For this basically you need to merge the php and HTML and then it works perfectly fine. My Experience says that you php only for logic and more of HTML for display
Here is my code

<a href="javascript:if (confirm('SURE YOU WANNA DELETE?')){window.location.href='index.php?option=com_enggaccount&task=removepostcodefromregion&engg_id=&postcode_id=' } else { void('') }; ">Delete

Display/Transport the php variables in JAVA script or alert Box

I do not know why this was hard for me, but I could not figure this out………this is a very simple logic to transport the php variable in java alert box

<?php
$notes = "RED KITE ISSUE!";
echo "<script type='text/javascript'>alert('{$notes}');</script>"
?>

ANOTHER METHOD

$notes="RedKite Issue.  Please Contact Simon regarding this product";			echo $notes;
echo "
 <script type='text/javascript'>
 alert('The variable has the following value: $notes');
 </script>
";

----------------------------------------------------
ANOTHER TO TRANSPORT THE VARIABLES

jsvar = ;
document.write(jsvar); // Test to see if its prints 10:

HOWEVER THIS NOT WORKED FOR ME
­čśŽ

http://www.skytopia.com/project/articles/compsci/form.html

—————————————————————————————————————————————————————————

Send variables between Javascript, Form and PHP on the same page:

PHP variable to Javascript variable:

	<?php   $myvar=10;   ?>

	<script type="text/javascript">
		jsvar = <?php echo $myvar; ?>;
		document.write(jsvar);  // Test to see if its prints 10:
	</script>

Form variable to Javascript variable:

	<form name="myform4">    <input type="hidden" name="formvar" value="100">     </form>

	<script type="text/javascript">
		jsvar = document.myform4.formvar.value;
		document.write(jsvar) // test
	</script>

PHP variable to Form variable:

	<form name="myform4">
		<input type="hidden" name="formvar" value="<?php phpvar=10; echo phpvar; ?>"> // PHP code inside HTML!!
	</form>

Javascript variable to Form variable:

	<form name="myform3">
		<!-- It needn't be a "hidden" type, but anything from radio buttons to check boxes -->
		<input type="hidden" name="formvar" value="">
	</form>

	<script type="text/javascript">
		jsvar=10;
		document.myform3.formvar.value = jsvar;
	</script>

Javascript variable to PHP variable:

This is impossible (unless you reload the page), since all PHP code is rendered first (on the server side), and then Javascript is dealt with afterwards (on the client side).

Form variable to PHP variable:

Impossible like above.


Pop window in php

Hi

I have struggling for hours to find a code purely in php for a popup window. The code is quite simple but a bit tricky. it requires java script to be integrated in the php code.  Here it is

  1. value1=urlencode('some value');

  2. echo "<a href=\"javascript :window.open('page.php?param1=$value1','name1','height=320,width=240');\">pop-up</a>";

For example I need to add a code in my php script to open a pop up window, here it is;

echo "<a href=\"javascript:window.open('editspares.php?id=$spareid&refno=$reference_id','Edit Spare Parts','height=50,width=650');\">Edit</a>";