In the practice of PHP and HTML mixed pages, PHP from the database to retrieve data after the loop output, then the linked JavaScript page how to get that each data corresponding ID value, is used for column classification
var fi= document.getElementById (LANMU). value;
In the PHP page
Alert only displays the FI and cannot display the ID value in the corresponding value
Reply to discussion (solution)
The page has not finished loading and the DOM object is not initialized, so document.getElementById (LANMU). value;
If the LANMU here is not a JS variable, enclose the quotation mark document.getElementById (' Lanmu '). Value
Suggested to
Window.load=function () { var fi= document.getelementbyid (LANMU). Value;}
or more convenient with jquery:
Also want to ask
JavaScript calls Document.getelementsbyid (LANMU). value; Then alert doesn't respond at all.
Document.getelementsbyname (LANMU), alert display undefine
What's the situation?
The page has not finished loading and the DOM object is not initialized, so document.getElementById (LANMU). value;
If the LANMU here is not a JS variable, enclose the quotation mark document.getElementById (' Lanmu '). Value
Suggested to
Window.load=function () { var fi= document.getelementbyid (LANMU). Value;}
or more convenient with jquery:
The first is yes, but the original JavaScript code needs to be all changed to jquery,
After joining jquery, clicking on the php page pops up the ID value of that column, and the question is how to turn the ID value into a variable in JavaScript
Try to write like this.
$ (function () {
var fid=$ (' #fi '). Val ();
});
Repeatedly pop-up prompt box, actually want to use FID variable, put the URL to pass out
Wrong, is the second kind of can
I don't know what you're going to do.
What you're describing doesn't exist in your code.
showtype.php: Used to display form form, the form has a level and the corresponding two level column name
Include (' conn/conn.php '); $SQLF = "SELECT * from Tb_class where supid=0";//select parent Data $sqlz = "SELECT * from Tb_class where supid!=0"; $shujuf =mysql_query ($SQLF); $shujuz =mysql_query ($SQLZ); ?>
javascript: Used to detect the previous form, set XMLHTTP URL, upload to changtype.php
function Modifytype (key) {
var nm = ' moditype1 ';
var fid = document.getElementById (FI). value;//this is not possible.
var fi= ' $fi ';//This is not possible.
var fid=$ (' #fi '). Val ();//This is not possible.
var names = document.getElementById (nm). Value;
if (names = = "") {
Alert (' Please fill in the category name ');
document.getElementById (NM). focus ();
return false;
}
var url = "changetype.php?action=m&names=" +names+ "&key=" +FID;
Xmlhttp.open ("GET", url,true);
Xmlhttp.onreadystatechange = check;
Xmlhttp.send (NULL);
}
function Delbigtype (key) {
if (Confirm ("Do you want to delete the first class, OK to delete it")) {
var url = "changetype.php?action=bd&key=" +FID;
Xmlhttp.open ("GET", url,true);
Xmlhttp.onreadystatechange = check;
Xmlhttp.send (NULL);
}else{
return false;
}
}
function Delsmalltype (key) {
if (Confirm ("OK to delete the selected item?"). Once deleted will not be restored! ")) {
var url = "changetype.php?action=sd&key=" +FID;
Xmlhttp.open ("GET", url,true);
Xmlhttp.onreadystatechange = check;
Xmlhttp.send (NULL);
}else{
return false;
}
}
function Check () {
if (xmlhttp.readystate = = 4) {
if (Xmlhttp.status = = 200) {
var msg = Xmlhttp.responsetext;
if (msg = = "1") {
Alert (' Duplicate class name ');
}else if (msg = = "2") {
Alert (' Operation failed! ');
}else (msg = = "3") {
Alert (' Operation succeeded ');
location= ' showtype.php ';
} else if (msg = = "4") {
Alert (' The big class has subclasses and cannot be deleted ');
}else (msg = = "0") {
Alert (' Unknown error! ') + ' \ n error code: ' +msg ';
}
}
}
}
There is also a changtype.php, used to modify the Add column
/**********************************
$reback Description:
0. Unknown error
1. Duplicate class name
2. Operation failed
3. Successful operation
4, there are two levels of classification
***********************************/
$conn =mysql_connect ("localhost", "root", "");
mysql_select_db ("Db_database22", $conn);
mysql_query ("Set names UTF8");
$action = $_get[' action '];//get the action in the JavaScript file
$reback = ";//Create a return variable
if ($action = = ' m ') {//If the action value is M?? Modify Column Name
$names = $_get[' names ');
$key = $_get[' key '];
$sql = "SELECT * from tb_class where name = ' $names '";
$rst = $conn->execute ($sql);//Execute Select Database
if ($rst->recordcount () = = 1) {//If selection succeeds
$reback = ' 1 ';//return value is 1
}else{
$updatesql = "SELECT * from tb_class where id =". $key;
$updaterst = $conn->execute ($updatesql);
$UPD = Array ();
$UPD ["id"] = $key;
$upd ["name"] = $names;
$update = $conn->getupdatesql ($updaterst, $UPD);//Modify Database
if ($conn->execute ($update) = = False) {//If the modification succeeds
$reback = ' 2 ';//return value is 2
}else{
$reback = ' 3 ';//return value is 3
}
}
}else if ($action = = ' SD ') {//If the action value is SD?? Delete sub-class columns
$key = $_get[' key '];
$delsql = "Delete from Tb_class where id =". $key;
if ($conn->execute ($delsql) = = False) {
$reback = ' 2 ';
}else{
$reback = ' 3 ';
}
}else if ($action = = ' bd ') {//If the action value is BD?? Delete the parent class column
$key = $_get[' key '];
$sql = "SELECT * from tb_class where supid =". $key;
$rst = $conn->execute ($sql);
if ($rst->recordcount () >= 1) {
$reback = ' 4 ';
}else{
$delsql = "Delete from Tb_class where id =". $key;
if ($conn->execute ($delsql) = = False) {
$reback = ' 2 ';
}else{
$reback = ' 3 ';
}
}
}else{
$reback = ' 0 ';
}
Echo $reback;
?>
Basic is the example of the book, the original is used Smarty template engine, want to change to not smary, found directly change not
Now there are a few questions:
1, document.getElementById (FI). Value does not take value, the point modification does not respond. After you add a onbur to the input hidden field, a popup box is displayed with only a 1
That is, "electronic class" data table ID, refresh all appear this, click on the other column modifier, is also 1, This column ID is not displayed. If you change the Inpu hidden style to not hide, you can display the ID of all columns. The PHP page has been taken to the ID value of each column, but the JavaScript page does not take the value of the input hidden field, which is The value.
2, the first PHP file, the parent class modified after the original is onclick= "Javascript:modifytype ({$key}), what this means, {$key} is the smarty template variable bar, how should this change?
3, Changtype.js function check () does not work what's going on? The class name repeats without prompting
Ajax+json, with jquery very convenient, direct support
With jquery you can get the values and iterate through the queries with each. Problem now every time you click on a button, refresh the prompt box to automatically pop out, loop to show the different values. I would like to press which key next to the pop-up corresponding value, rather than automatic prompt, now do not know how to set.
$ ("button"). Click (function () {
$ ("Input:hidden"). each (function () {
Alert ($ (this). Val ())