-3

I am in trouble in my project.

When my page is loded, I need to define a value from DB with ajax to A[] in my html web code.

The DB SQL is:

<?php
includes("DB.php");//for connecting and log on DB
select count(*) as total from  OA where  handleP='John' and stat='suspending';
?>

The total maybe is 0,or 1, or others;

So A[] maybe is A[0], or maybe A[1], or others.

A[] default value is A[0]. How to define it?

Here is html code:

<a href="javascript:void(0)" class="easyui-linkbutton" onclick="standbyDoc()">A[0]</a><br />
Snow
  • 71
  • 1
  • 11
  • Possible duplicate of [What is the correct way to write HTML using Javascript?](https://stackoverflow.com/questions/1533568/what-is-the-correct-way-to-write-html-using-javascript) – Obsidian Age Feb 23 '18 at 01:37
  • Use `document.write()`, `.createTextNode()` or `.innerHTML` depending on your needs. – Obsidian Age Feb 23 '18 at 01:37
  • @ObsidianAge, please see my update. Thankyou for your kindly hearted – Snow Feb 23 '18 at 02:25
  • @ObsidianAge, my question is different from What is the correct way to write HTML using Javascript? – Snow Feb 23 '18 at 02:59

1 Answers1

0

As @ObsidianAge said, it depends on your needs. If your real case is as simple as provided code, you can get necessary HTML element and use innerHTML (for example). It should be something like this:

var A = ['test'];
document.getElementsByClassName("easyui-linkbutton")[0].innerHTML = A[0];
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="standbyDoc()">A[0]</a><br />
P.S.
  • 15,970
  • 14
  • 62
  • 86