embeded javascript in php

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
minos_mks
Forum Commoner
Posts: 69
Joined: Thu Feb 04, 2010 1:58 am

embeded javascript in php

Post by minos_mks »

hi ,

i have 2 php file and those files contain javascript code to make to combobox conected with the database to make the user select first the name of the state and depend on what he select the other combobox make him select the city of this state

so those the 2 file

1-search_jobs_state.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Ajax Tutorial: Dynamic Loading of ComboBox using jQuery and Ajax in PHP</title>
<link href="../Css/Main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery-1.3.2.js"></script>

<script type="text/javascript">

$(document).ready(function() {

$('#loader').hide();
$('#show_heading').hide();

$('#search_category_id').change(function(){
$('#show_sub_categories').fadeOut();
$('#loader').show();
$.post("search_jobs_get_city.php", {
parent_id: $('#search_category_id').val(),
}, function(response){

setTimeout("finishAjax('show_sub_categories', '"+escape(response)+"')", 400);
});
return false;
});
});

function finishAjax(id, response){
$('#loader').hide();
$('#show_heading').show();
$('#'+id).html(unescape(response));
$('#'+id).fadeIn();
}

function alert_id()
{
if($('#sub_category_id').val() == '')
alert('Please select a sub category.');
else
alert($('#sub_category_id').val());
return false;
}

</script>
<style>

</style>
</head>
<?php require("../includes/connection.php"); ?>
<body>

<h1>Dynamic Loading of ComboBox using jQuery and Ajax in PHP </h1>

<br clear="all" /><br clear="all" /><br clear="all" />

<div style="padding-left:30px;">
<form action="#" name="form" id="form" method="post" onsubmit="return alert_id();" enctype="multipart/form-data">

<div class="both">
<h4>Select Category</h4>
<select name="search_category" id="search_category_id">
<option value="" selected="selected"></option>
<?php
$query = "select distinct state_name from zip_code ORDER BY state_name ";
$results = mysql_query($query);

while ($rows = mysql_fetch_assoc(@$results))
{?>
<option value="<?php echo $rows['state_name'];?>"><?php echo $rows['state_name'];?></option>
<?php
}?>
</select>
</div>

<div class="both">
<h4 id="show_heading">Select Sub Category</h4>
<div id="show_sub_categories" align="center">
<img src="loader.gif" style="margin-top:8px; float:left" id="loader" alt="" />
</div>
</div>
<br clear="all" /><br clear="all" />

<input type="submit" name="" value="GO" />
</form>
</div>
<br clear="all" /><br clear="all" /><br clear="all" />

</body>
</html>
--------------------------------------------------------------------------------------------------------------------
2-search_jobs_get_city.php

<?php

require_once("../includes/connection.php");

if($_REQUEST)
{
$id = $_REQUEST['parent_id'];
$query = "select distinct city from zip_code where state_name = \"$id\" ORDER BY city ";
$results = mysql_query( $query);?>

<select name="sub_category" id="sub_category_id">
<option value="" selected="selected"></option>
<?php
while ($rows = mysql_fetch_assoc(@$results))
{?>
<option value="<?php echo $rows['city'];?>ID=<?php echo $rows['city'];?>"><?php echo $rows['city'];?></option>
<?php
}?>
</select>

<?php
}
?>

---------------------------------------------------------------------------------------------------

and this is the file that i wanna the last 2 file to embedded it (this file is like on form to save data to database and i suppose save state and city ):


<?php session_start(); ?>
<html>

<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php include("includes/header.php"); ?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Add A New Job Ad</title>
<link href="Css/Main.css" rel="stylesheet" type="text/css" />
<style type="text/css">

</style>
</head>

<body class="thrColFixHdr">
<div id="container">
<div id="header">

<!-- end #header --></div>
<div id="sidebar1">

<?php require_once("sidebar1.php"); ?>
<?php require_once("sidebar1b.php"); ?>

<!-- end #sidebar1 --></div>
<div id="sidebar2">
<?php require_once("sidebar2.php"); ?>
<?php require_once("sidebar2b.php"); ?>

<!-- end #sidebar2 --></div>


<div id="mainContent">
<?php
if (isset($_SESSION['user_name'])){
echo " " ;
}
else { die("you have to login firest");}
?>
<h4 align="center">Posting A New Ad For Donation</h4>


<form action="add_ad_result.php" method="POST" enctype='multipart/form-data'>

<table align="center" border="0" cellspacing="1" width="40%">
<tr>
<td bgcolor="#CCCCCC" width="10" >disc</td>
<td ><input name=disc type="text" size="90" ></td>

</tr>
<tr>
<td bgcolor="#CCCCCC"> First Name</td>
<td ><input name="first_Name" type="text" id="address" size="50" maxlength="90"></td>
<td bgcolor="#CCCCCC"> Last Name</td>
<td ><input name="last_Name" type="text" id="address" size="50" maxlength="90"></td>
</tr>
<tr>
<td bgcolor="#CCCCCC"> phone</td>
<td ><input name="phone" type="text" id="address" size="50" maxlength="90"></td>
<td bgcolor="#CCCCCC"> E-Mail</td>
<td ><input name="email" type="text" id="address" size="50" maxlength="90"></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">Address</td>
<td ><input name="address" type="text" id="address" size="50" maxlength="90"></td>
</tr>
<tr>
</tr>
<tr>

<td bgcolor="#CCCCCC">Donation Type</td>
<td><select name="categ">
<?php
$categs=select_categ(categs);
$categ = mysql_fetch_assoc($categs);
do {
?>
<option value="<?php echo $categ['furnisher_categ_code']?>"><?php echo $categ['furnisher_categ_name']?></option>
<?php
} while ($categ = mysql_fetch_assoc($categs));
$categs = mysql_num_rows($categ);
if($categs > 0) {
mysql_data_seek($categ, 0);
//$row_Recordset1 = mysql_fetch_assoc($model);
}
?>
</select>
</td>
<td bgcolor="#CCCCCC" width="30">Rating of Condition</td>
<td><select name="rating" id="count">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select></td>
</tr>
<tr>
<td bgcolor="#CCCCCC" width="30">Count of items</td>
<td><select name="count" id="count">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select></td>
<td bgcolor="#CCCCCC" width="30">Shiping Police</td>
<td><select name="shiping" id="shiping">
<option value="2">pick it up</option>
<option value="1">Recive it </option>
</select></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">pic1</td>
<td><input type="file" name="image_name1" size="10"></td>
<td bgcolor="#CCCCCC">pic2</td>
<td><input type="file" name="image_name2" size="10"></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">pic3</td>
<td><input type="file" name="image_name3" size="10"></td>
<td bgcolor="#CCCCCC">pic4</td>
<td><input type="file" name="image_name4" size="10"></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">pic5</td>
<td><input type="file" name="image_name5" size="10"></td>
<td bgcolor="#CCCCCC">pic6</td>
<td><input type="file" name="image_name6" size="10"></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">pic7</td>
<td><input type="file" name="image_name7" size="10"></td>
<td bgcolor="#CCCCCC">pic8</td>
<td><input type="file" name="image_name8" size="10"></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">pic9</td>
<td><input type="file" name="image_name9" size="10"></td>
<td bgcolor="#CCCCCC">pic10</td>
<td><input type="file" name="image_name10" size="10"></td>
</tr>
<tr>
<td bgcolor="#CCCCCC" colspan="8" align="center">note</td>
<td><input type="hidden" name="table_number" value="6" /></td>
</tr>
<tr>
<td height="318" colspan="8"><textarea name="note" id="note" cols="90" rows="20"></textarea></td>
</tr>
<tr>
<td><input type="submit" name="save" id="save" value="Post the Ad" align="middle"></td>
</tr>
</table>
</form>
<!-- end #mainContent --></div>
<!-- This clearing element should immediately follow the
#mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
<div id="footer">
<?php require_once("includes/footer.php"); ?>
<!-- end #footer --></div>
<!-- end #container --></div>
</body>
</html>
<?php
//mysql_free_result($Recordset1);
?>
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: embeded javascript in php

Post by kaszu »

Please use [syntax][/syntax] when posting code ( viewtopic.php?f=13&t=21171 ), use "edit".
Also explain what's the problem you are having.
Post Reply