php 변수을 javascript 에서 쓰고 싶을때 팁~

  • authorbibaram
  • 02 January 2006, 15:55:25

<html>
<head>
</head>
<script>
function click_a()
{
  var st_v
  st_v = document.all.test01.value;
  htmledit.document.location = "aa.php?chem=" + st_v;
  var timerId = setTimeout( click_b, 10 );
}

function click_b()
{
  if(htmledit.document.all.chem.value != null ) {
  document.all.test02.value = htmledit.document.all.chem.value;
  return;
 }
  var timerId = setTimeout( click_b, 10);
}

function click_c()
{
 var st_v;
 st_v = document.all.test01.value;
 htmledit.document.location = "aa.php?return_v=NEW&chem=" + st_v;
 var timerId = setTimeout(click_d, 10);
 }
 
function click_d()
 {
  if(htmledit.document.all.list.length != 0 ) {
  var list_v = htmledit.document.all.list.length;
  document.all.list.length = list_v;
  for(var i=0;i<list_v;i++) {
  document.all.list.options[i].text = htmledit.document.all.list[i].value;
 document.all.list.options[i].value = i;
   } 
  return;
  }
  var timerId = setTimeout( click_b, 10);
}
</script>
<body>
<form>
<input type=text name=test01>
<input type=text name=test02>
<select name="list" style="background-color:#808080; font-family:Tahoma; Font-size:8pt; color:#FFFFFF">
<option value="1">첫번째</option>
<option value="2">두번째</option>
<option value="3">세번째</option>
</select>
<img src="/img/button/query.gif" width="46" height="16" border="0" onclick="javascript:click_a();">
<img src="/img/button/query.gif" width="46" height="16" border="0" onclick="javascript:click_c();">
</form>
<iframe src="aa.php" name="htmledit" width="0" height= "0">
</iframe>
</body>
</html>

aa.php
<?
$host="localhost";
$user="root";
$pwd="";
$db="";
$connect=@mysql_connect($host,$user,$pwd) or die("mysqlserver connect failed");
$db=@mysql_select_db($db) or die("mysqldb connect failed");
mysql_query("set session character_set_results=euckr;");
mysql_query("set session character_set_connection=euckr;");

switch($return_v)
{
 Case "NEW" :
 $query = "";
  $result = mysql_query($query);
  while($row = mysql_fetch_array($result))
  {
  echo "<input type='hidden' name='list' value='".$row[0]."' >";
  }
  echo "<script>document.reload();</scrpt>";
   break;
   default:
?>

<!-- ##########################################################################################  -->
<!-- 일반                                                                                        -->
<!-- ########################################################################################## -->
  <html>
  <head>
  </head>
  <body>
  <?
  $query = "";
  $result = mysql_query($query);
  $row = mysql_fetch_array($result);
  echo "<input type='hidden' name='chem' value='".$row[0]."' >";
  echo "<script>document.reload();</scrpt>";
  ?>
  </body>
  </html>
<?
  break;
}
?>

보면 아하~~ 할꺼에여
submit 않하구 Ifram으로 php 결과값을 구해서 다시 자바스크립트로
넘겨준는 내용인되
반응속도가 영 낮아서 타임으로 약간의 기다림을 주었음 -ㅁ-
결과가 궁금하면 한번 긁어다가 써보심이  ㅎㅎ

Press ESC to close