manish patel
manish patel

Reputation: 1449

javascript in php passing value to javascript value

I have use code as shown below:

  <?  
$sql = mysql_query("select * from tbl_item where item_category = '$item_cat'");
$i=1;
  while($crows = mysql_fetch_array($sql))
  {
    ;
  ?>    

  <tr>
    <td width="57" align="center" ><? echo $i;?></td>
    <td width="540" align="center" onClick=><div align="center"><? echo $crows["item_name"];?> </div></td>
    <td width="385" align="center">
      1<input name="<? echo $crows["item_name"];?>" type="radio" id="radioqty<? echo $i;?>" value="1" checked="checked"  />

      2<input type="radio" name="<? echo $crows["item_name"];?>" id="radioqty<? echo $i;?>" value="2" />

      3<input type="radio" name="<? echo $crows["item_name"];?>" id="radioqty<? echo $i;?>" value="3" />

      4<input type="radio" name="<? echo $crows["item_name"];?>" id="radioqty<? echo $i;?>" value="4" />
    </td>
    <td width="249" align="center" >
      Full<input name="radioplate<? echo $i?>" type="radio" id="radioplate<? echo $i?>" value="full" checked="checked" /> 
      Half<input type="radio" name="radioplate<? echo $i?>" id="radioplate<? echo $i?>" value="half" /></td>

    <td width="281" align="center">
      <input name="serve" type="button" value="Serve" onclick="get_code('a','get_item_save.php?item_id='+<? echo $crows["item_id"];?>+'&cat_id='+document.exB.item_category.value+'&plate_type='+document.exB.radioplate<? echo $i?>.value+'&qty='+exB.radioqty<? echo $i;?>.value+'&bill_no='+document.exB.bill_summary_bill_no.value+'&bill_date='+document.exB.bill_summary_date.value),get_code('b','get_item_sale_list.php?bill_no='+document.exB.bill_summary_bill_no.value)"/>      </td>
  </tr>
  <? $i++; }?>

Here I'm doing something wrong when I call get_code function and I'm unable to figure out were I'm wrong. Could someone figure out what I'm doing wrong on this line of code:

<td width="281" align="center">
    <input name="serve" type="button" value="Serve" onclick="get_code('a','get_item_save.php?item_id='+<? echo $crows["item_id"];?>+'&cat_id='+document.exB.item_category.value+'&plate_type='+document.exB.radioplate<? echo $i?>.value+'&qty='+exB.radioqty<? echo $i;?>.value+'&bill_no='+document.exB.bill_summary_bill_no.value+'&bill_date='+document.exB.bill_summary_date.value),get_code('b','get_item_sale_list.php?bill_no='+document.exB.bill_summary_bill_no.value)"/>      </td>

I get an error at: document.exB.radioplate<? echo $i?>.value show undefined.

Upvotes: 0

Views: 59

Answers (1)

Maybe with mysql_fetch_array($sql, MYSQL_ASSOC) in the while statement.

With the MYSQL_ASSOC you can retrieve the fields by its name, like crows['item_name'].

Upvotes: 1

Related Questions