PDA

View Full Version : java sript + php



rash44
یک شنبه 13 فروردین 1391, 10:40 صبح
با سلام
لطفا این کد را بررسی کنید

کاربر پس از کلیک بر روی دکمه ایجاد سطر جدید , فیلد نام کالا بصورت تکمیل شده چاپ نمی شود . فقط یک drop down box خالی چاپ میشه

در حالی که تنظیم شده که اطلاعات این فیلد از دیتابیس گرفته شود

آیا امکان دارد که 1 متغیر php در جاوا اسکریپت استفاده شود ؟؟؟؟؟؟؟



<?php
ob_start();
session_start();
$ClientString = $_SERVER['HTTP_USER_AGENT'];
if(!isset($_SESSION['user']) || $_SESSION['ClientStr'] != md5($ClientString))
{
header("location:../index.php");
}
require_once('../inc/config.php');
$db = db_connect();
$sql="SELECT `id`,`name` FROM `typekala`";
$result = mysql_query($sql);
while($inf=mysql_fetch_assoc($result)) {
$sql2="SELECT `id`,`name` FROM `kala` WHERE `type`='$inf[id]'";
$result2 = mysql_query($sql2);
while($inf2=mysql_fetch_assoc($result2)) {
$option="
<option value=$inf[id]>::: $inf[name] :::</option>
<option value=$inf2[id]>$inf2[name]</option>";
} } ?>
<html>
<head>
<meta http-equiv="Content-Language" content="fa">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="../inc/Template.css">
<script>
function addrow()
{
var tl=document.getElementById("t1");
var row=tl.insertRow(tl.rows.length);
var cell=row.insertCell(0);
var cell2=row.insertCell(1);
cell.innerHTML="<input type=text name=count[] size=20 dir=rtl maxlength=10 class=in>";
cell2.innerHTML="<select size=1 name=kala[] dir=rtl class=in>'$option'</select>";
}
</script>
</head>
<body>
<table border="0" width="100%" style="border: 3px double #333333; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px">
<form method="POST" action="Frmaddklatoanbstep2.php" name="form">
<tr>
<td>
<table border="0" width="100%">
<tr>
<td>
<input type="button" value="ایجاد سطر جدید" onclick="return addrow();" class="button" style="float: right"></td>
</tr>
<tr>
<td>
<table border="0" width="100%" cellpadding="2" id="t1">
<tr>
<td align="center" height="25" width="20%" bgcolor="#006699">
<font face="Tahoma" style="font-size: 9pt" color="#FFFFFF">
تعداد</font></td>
<td align="center" height="25" width="70%" bgcolor="#006699">
<font face="Tahoma" style="font-size: 9pt" color="#FFFFFF">
نام کالا</font></td>
</tr>
<tr>
<td height="25" width="20%" align="center">
<input type="text" name="count[]" size="20" dir="ltr" maxlength="10" class="in"></td>
<td height="25" width="70%" align="center">&nbsp;</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
&nbsp;</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<p align="center">
<input type="submit" value="مرحله بعد" class="button" name="btn" onclick="return checkform();"><span lang="en-us">&nbsp;
</span><input type="reset" value="فرم جدید" class="button"></td>
</tr>
</form>
</table>
</body>
</html>

MMSHFE
یک شنبه 13 فروردین 1391, 10:43 صبح
اون جایی که توی جاوا اسکریپت نوشتین option$ باید بنویسید <? ;php echo $option?>
موفق باشید.

rash44
یک شنبه 13 فروردین 1391, 10:53 صبح
کد جدید


<?php
ob_start();
session_start();
$ClientString = $_SERVER['HTTP_USER_AGENT'];
if(!isset($_SESSION['user']) || $_SESSION['ClientStr'] != md5($ClientString))
{
header("location:../index.php");
}
require_once('../inc/config.php');
$db = db_connect();
$sql="SELECT `id`,`name` FROM `typekala`";
$result = mysql_query($sql);
while($inf=mysql_fetch_assoc($result)) {
$sql2="SELECT `id`,`name` FROM `kala` WHERE `type`='$inf[id]'";
$result2 = mysql_query($sql2);
while($inf2=mysql_fetch_assoc($result2)) {
$option="
<option value=$inf[id]>::: $inf[name] :::</option>
<option value=$inf2[id]>$inf2[name]</option>";
} } ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>سیستم یکپارچه مالی رهیاب</title>
<link rel="stylesheet" type="text/css" href="../inc/Template.css">
<script>
function addrow()
{
var tl=document.getElementById("t1");
var row=tl.insertRow(tl.rows.length);
var cell=row.insertCell(0);
var cell2=row.insertCell(1);
cell.innerHTML="<input type=text name=count[] size=20 dir=rtl maxlength=10 class=in>";
cell2.innerHTML="<select size=1 name=kala[] dir=rtl class=in><?php echo $option; ?></select>";
}
</script>
</head>
<body>
<table border="0" width="100%" style="border: 3px double #333333; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px">
<form method="POST" action="Frmaddklatoanbstep2.php" name="form">
<tr>
<td>
<table border="0" width="100%">
<tr>
<td>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="56">
<font color="#003366"><b>
<input type="reset" value="برگشت" class="button" onclick="history.back()"></td>
<td>
<p align="center" dir="rtl"><b>
<font face="Arial" color="#333333">فرم ورود کالا به انبار</font></b></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<input type="button" value="ایجاد سطر جدید" onclick="return addrow();" class="button" style="float: right"></td>
</tr>
<tr>
<td>
<table border="0" width="100%" cellpadding="2" id="t1">
<tr>
<td align="center" height="25" width="20%" bgcolor="#006699">
<font face="Tahoma" style="font-size: 9pt" color="#FFFFFF">
تعداد</font></td>
<td align="center" height="25" width="70%" bgcolor="#006699">
<font face="Tahoma" style="font-size: 9pt" color="#FFFFFF">
نام کالا</font></td>
</tr>
<tr>
<td height="25" width="20%" align="center">
<input type="text" name="count[]" size="20" dir="ltr" maxlength="10" class="in"></td>
<td height="25" width="70%" align="center">
<select dir="rtl" class="in" name="kala[]" size="1">
<?php echo $option; ?>
</select>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
&nbsp;</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<p align="center">
<input type="submit" value="مرحله بعد" class="button" name="btn" onclick="return checkform();"><span lang="en-us">&nbsp;
</span><input type="reset" value="فرم جدید" class="button"></td>
</tr>
</form>
</table>
</body>
</html>


با کاری که شما فرمودین دیگه هیچ رکوردی اضاف نمیشه

rash44
یک شنبه 13 فروردین 1391, 11:28 صبح
لطفا راهنمائی کنید

MMSHFE
یک شنبه 13 فروردین 1391, 11:31 صبح
این کد رو ببینید:


<?php
ob_start();
$option = '';
session_start();
$ClientString = $_SERVER['HTTP_USER_AGENT'];
if(!isset($_SESSION['user']) || $_SESSION['ClientStr'] != md5($ClientString)) {
header('location: ../index.php');
exit();
}
require_once '../inc/config.php';
$db = db_connect();
$sql = 'SELECT `id`,`name` FROM `typekala`';
$result = mysql_query($sql);
if($result && mysql_num_rows($result) > 0) {
while($inf = mysql_fetch_assoc($result)) {
$sql2 = "SELECT `id`,`name` FROM `kala` WHERE `type`='{$inf['id']}'";
$result2 = mysql_query($sql2);
if($result2 && mysql_num_rows($result2) > 0) {
while($inf2 = mysql_fetch_assoc($result2)) {
$option .= "<option value=\"{$inf['id']}\">::: {$inf['name']} :::</option>";
$option .= "<option value=\"{$inf2['id']}\">{$inf2['name']}</option>";
}
}
}
}
?>
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Language" content="fa"/>
<meta charset="utf-8"/>
<title></title>
<link href="../inc/Template.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript">
function addrow() {
var tl = document.getElementById("t1");
var row = tl.insertRow(tl.rows.length);
var cell = row.insertCell(0);
var cell2 = row.insertCell(1);
cell.innerHTML = "<input type=\"text\" name=\"count[]\" size=\"20\" dir=\"rtl\" maxlength=\"10\" class=\"in\">";
cell2.innerHTML = "<select size=\"1\" name=\"kala[]\" dir=\"rtl\" class=\"in\"><?php echo $option; ?></select>";
}
</script>
</head>
<body>
<form action="Frmaddklatoanbstep2.php" method="post" name="form">
<table border="0" id="t1" style="border: 3px double #333333; padding-left: 4px; padding: 1px 4px;" width="100%">
<tr>
<td colspan="2">
<input type="button" value="ایجاد سطر جدید" onclick="return addrow();" class="button" style="float: right"/>
</td>
</tr>
<tr align="center" height="25px">
<th width="20%" bgcolor="#006699">
<font face="Tahoma" style="font-size: 9pt" color="#ffffff">تعداد</font>
</th>
<th width="80%" bgcolor="#006699">
<font face="Tahoma" style="font-size: 9pt" color="#ffffff">نام کالا</font>
</th>
</tr>
<tr align="center" height="25px">
<td>
<input type="text" name="count[]" size="20" dir="ltr" maxlength="10" class="in"/>
</td>
<td>&nbsp;</td>
</tr>
<tr align="center">
<td colspan="2">
<input class="button" name="btn" onclick="return checkform();" type="submit" value="مرحله بعد"/>
<input class="button" type="reset" value="فرم جدید"/>
</td>
</tr>
</table>
</form>
</body>
</html>
میگم شما با DW صفحه رو طراحی کردین که اینهمه table تو در تو دارین؟

rash44
یک شنبه 13 فروردین 1391, 11:34 صبح
با تشکر از شما
لطفا فایل را برام ارسال کنید
چون این کد خیلی به هم ریخته هست

ممنون میشم

rash44
یک شنبه 13 فروردین 1391, 11:43 صبح
از کد شما هم استفاده کردم اما باز هم هیچ رکوردی اضافه نمیشه


<?php
ob_start();
$option = '';
session_start();
$ClientString = $_SERVER['HTTP_USER_AGENT'];
if(!isset($_SESSION['user']) || $_SESSION['ClientStr'] != md5($ClientString)) {
header('location: ../index.php'); exit();
}
require_once '../inc/config.php';
$db = db_connect();
$sql = 'SELECT `id`,`name` FROM `typekala`';
$result = mysql_query($sql);
if($result && mysql_num_rows($result) > 0) {
while($inf = mysql_fetch_assoc($result)) {
$sql2 = "SELECT `id`,`name` FROM `kala` WHERE `type`='{$inf['id']}'";
$result2 = mysql_query($sql2);
if($result2 && mysql_num_rows($result2) > 0) {
while($inf2 = mysql_fetch_assoc($result2)) {
$option .= "<option value=\"{$inf['id']}\">::: {$inf['name']} :::</option>";
$option .= "<option value=\"{$inf2['id']}\">{$inf2['name']}</option>";
} } } } ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>سیستم یکپارچه مالی رهیاب</title>
<link rel="stylesheet" type="text/css" href="../inc/Template.css">
<script type="text/javascript">
function addrow() {
var tl = document.getElementById("t1");
var row = tl.insertRow(tl.rows.length);
var cell = row.insertCell(0);
var cell2 = row.insertCell(1);
cell.innerHTML = "<input type=text name=count[] size=20 dir=rtl maxlength=10 class=in>";
cell2.innerHTML = "<select size=1 name=kala[] dir=rtl class=in><?php echo $option; ?></select>";
} </script>
</head>
<body>
<table border="0" width="100%" style="border: 3px double #333333; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px">
<form method="POST" action="Frmaddklatoanbstep2.php" name="form">
<tr>
<td>
<table border="0" width="100%">
<tr>
<td>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="56">
<font color="#003366"><b>
<input type="reset" value="برگشت" class="button" onclick="history.back()"></td>
<td>
<p align="center" dir="rtl"><b>
<font face="Arial" color="#333333">فرم ورود کالا به انبار</font></b></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<input type="button" value="ایجاد سطر جدید" onclick="return addrow();" class="button" style="float: right"></td>
</tr>
<tr>
<td>
<table border="0" width="100%" cellpadding="2" id="t1">
<tr>
<td align="center" height="25" width="20%" bgcolor="#006699">
<font face="Tahoma" style="font-size: 9pt" color="#FFFFFF">
تعداد</font></td>
<td align="center" height="25" width="70%" bgcolor="#006699">
<font face="Tahoma" style="font-size: 9pt" color="#FFFFFF">
نام کالا</font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
&nbsp;</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<p align="center">
<input type="submit" value="مرحله بعد" class="button" name="btn" onclick="return checkform();"><span lang="en-us">&nbsp;
</span><input type="reset" value="فرم جدید" class="button"></td>
</tr>
</form>
</table>
</body>
</html>

rash44
یک شنبه 13 فروردین 1391, 11:49 صبح
خروجی کد شما :
85035

MMSHFE
یک شنبه 13 فروردین 1391, 11:49 صبح
راستش اینطوری نمیتونم دقیقاً بگم مشکل کجاست. باید کل اسکریپت رو داشته باشم تا بتونم تست کنم و مشکل رو پیدا کنم.

rash44
یک شنبه 13 فروردین 1391, 11:57 صبح
فایل پروژه

MMSHFE
یک شنبه 13 فروردین 1391, 11:59 صبح
این عکس، خروجی کدی هست که گذاشتم:
85037

MMSHFE
یک شنبه 13 فروردین 1391, 12:15 عصر
کد اصلاح شده رو ضمیمه کردم.

rash44
یک شنبه 13 فروردین 1391, 12:21 عصر
ممنونم دوست عزیز

الان به چه صورتی می تونم drop down box را به این صورت طراحی کنم ؟؟

عنوان دسته 1
نام کالاهای زیر مجموعه
نام کالاهای زیر مجموعه
نام کالاهای زیر مجموعه
نام کالاهای زیر مجموعه
عنوان دسته 2
نام کالاهای زیر مجموعه
نام کالاهای زیر مجموعه
نام کالاهای زیر مجموعه
نام کالاهای زیر مجموعه
نام کالاهای زیر مجموعه

می دونم که 1 tag برای این کار وجود داره

ممنون میشم اگر این هم راهنمائیم کنید

MMSHFE
یک شنبه 13 فروردین 1391, 13:23 عصر
<?php
ob_start();
$option = '';
session_start();
$ClientString = $_SERVER['HTTP_USER_AGENT'];
if(!isset($_SESSION['user'], $_SESSION['ClientStr']) || $_SESSION['ClientStr'] != md5($ClientString)) {
//header('location:index.php');
//exit();
}
require_once 'inc/config.php';
$db = db_connect();
$sql = 'SELECT `id`,`name` FROM `typekala`';
$result = mysql_query($sql);
if($result && mysql_num_rows($result) > 0) {
while($inf = mysql_fetch_assoc($result)) {
$option .= "<optgroup label=\\\"::: {$inf['name']} :::\\\">";
$sql2 = "SELECT `id`,`name` FROM `kala` WHERE `type`='{$inf['id']}'";
$result2 = mysql_query($sql2);
if($result2 && mysql_num_rows($result2) > 0) {
while($inf2 = mysql_fetch_assoc($result2)) {
$option .= "<option value=\\\"{$inf2['id']}\\\">{$inf2['name']}</option>";
}
}
$option .= "</optgroup>";
}
}
?>
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Language" content="fa"/>
<meta charset="utf-8"/>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
function addrow() {
var tl = document.getElementById("t1");
var row = tl.insertRow(tl.rows.length);
var cell = row.insertCell(0);
var cell2 = row.insertCell(1);
cell.innerHTML = "<input type=\"text\" name=\"count[]\" size=\"20\" dir=\"rtl\" maxlength=\"10\" class=\"in\">";
cell2.innerHTML = "<select size=\"1\" name=\"kala[]\" dir=\"rtl\" class=\"in\"><?php echo $option; ?></select>";
}
</script>
</head>
<body>
<form action="Frmaddklatoanbstep2.php" method="post" name="form">
<table border="0" id="t1" style="border: 3px double #333333; padding-left: 4px; padding: 1px 4px;" width="100%">
<tr>
<td colspan="2">
<input type="button" value="ایجاد سطر جدید" onclick="return addrow();" class="button" style="float: right"/>
</td>
</tr>
<tr align="center" height="25px">
<th width="20%" bgcolor="#006699">
<font face="Tahoma" style="font-size: 9pt" color="#ffffff">
تعداد</font>
</th>
<th width="80%" bgcolor="#006699">
<font face="Tahoma" style="font-size: 9pt" color="#ffffff">
نام کالا</font>
</th>
</tr>
<tr align="center" height="25px">
<td>
<input type="text" name="count[]" size="20" dir="ltr" maxlength="10" class="in"/>
</td>
<td>&nbsp;</td>
</tr>
</table>
<table width="100%">
<tr align="center">
<td colspan="2">
<input class="button" name="btn" onclick="return checkform();" type="submit" value="مرحله بعد"/>
<input class="button" type="reset" value="فرم جدید"/>
</td>
</tr>
</table>
</form>
</body>
</html>

به چگونگی استفاده از تگ optgroup دقت کنید.

MMSHFE
دوشنبه 14 فروردین 1391, 01:21 صبح
لطفاً بعد از گرفتن پاسخ، تاپیک را حذف نکنید. شاید مشکل شما برای سایرین هم پیش آمده باشد و بتواند به آنها در حل مشکلشان کمک کند. موفق باشید.