Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php JavaScript getElementById()获取数据时出现问题_Php_Javascript_Html - Fatal编程技术网

Php JavaScript getElementById()获取数据时出现问题

Php JavaScript getElementById()获取数据时出现问题,php,javascript,html,Php,Javascript,Html,好:我有如下HTML代码: <form method="post"> <ul> <li> <label for="username">Username</label> <input type="text" id="username" size="30" onblur="checkUser()" /> <div id=user></div> <

好:我有如下HTML代码:

<form method="post">
  <ul>
    <li>
      <label for="username">Username</label>
      <input type="text" id="username" size="30" onblur="checkUser()" />
      <div id=user></div>
    </li>
    <li>
      <label for="email">Email</label>
      <input type="text" name="email" id="email" size="30" />
    </li>
    <li>
      <label for="first_name">First Name</label>
      <input type="text" name="first_name" id="first_name" size="30" />
    </li>
    <li>
      <label for="last_name">Last Name</label>
      <input type="text" name="last_name" id="last_name" size="30" />
    </li>
    <li>
      <label for="cell">Cell</label>
      <input type="text" name="cell" id="cell" size="30" />
    </li>
    <li>
      <label for="street">Street</label>
      <input type="text" name="street" id="street" size="30" />
    </li>
    <li>
      <label for="city">City</label>
      <input type="text" name="city" id="city" size="30" />
    </li>
    <li>
            <label for="zip">Zip</label>
      <input type="text" name="zip" id="zip" size="30" />
    </li>
    <li>
            <label for="password">Password</label>
      <input type="password" name="password" id="password" size="30" />
    </li>
    <li><label for="password2">Repeat Password</label>
      <input type="password" name="password2" id="password2" size="30" />
    </li>
    <li>
            <label for="submit"></label>
      <button type="submit" name="submit" id="submit">Register</button>
    </li>
  <ul>
</form>
我被困在
document.getElementById('username').value。警报显示值为
username

我正试图使用此函数从上述文本框中提取值,并将其传递给
userCheck.php
进行查询,以查看用户名是否已被使用

有什么帮助吗

更新-代码的其余部分

<? include "heading.php" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<?php
function mailer($to,$username,$hash){

        $subject = "Test mail";
        $message = "http://www.me.com/verify.php?username=$username&hash=$hash";
        $from = "me@myself.com";
        $headers = "From:" . $from;
        mail($to,$subject,$message,$headers);
        echo "Mail Sent.";

    }

if(isset($_POST['submit'])){
        if($_POST['password']==$_POST['password2'] && !empty($_POST['password']) && !empty($_POST['username']) && !empty($_POST['email']) && !empty($_POST['last_name'])){
            if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])){
                $msg = 'The email you have entered is invalid, please try again.';  
                }else{
                    require_once "UserManagement.php";
                    $hash = md5(rand(0,1000));
                    $usman=new UserManagement();
                    $usman->createUser($_POST['username'],$_POST['email'],$_POST['first_name'],$_POST['last_name'],$_POST['cell'],$_POST['street'],$_POST['city'],$_POST['zip'],md5($_POST['password']),$hash);
                    mailer($_POST['email'],$_POST['username'],$hash);
                    $msg = 'Your account has been made, <br /> please verify it by clicking the activation link that has been send to your email.';  
                    header('Location: http://www.me.com/me');
                    }
                    }else{
                        $msg = 'Form Data Incorrect';
                        sleep(10);
                        header('Location:http://www.me.com/me');

                    }
}

?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Registration</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="css/templatemo_style.css" rel="stylesheet" type="text/css" />




<script language="javascript" type="text/javascript">
function clearText(field)
{
    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;
}
</script>

<link rel="stylesheet" type="text/css" href="css/ddsmoothmenu.css" />

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/ddsmoothmenu.js">

/***********************************************
* Smooth Navigational Menu- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

</script>

<script type="text/javascript">

ddsmoothmenu.init({
    mainmenuid: "templatemo_menu", //menu DIV id
    orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
    classname: 'ddsmoothmenu', //class added to menu's outer DIV
    //customtheme: ["#1c5a80", "#18374a"],
    contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})

</script>

</head>
<body id="sub_page">
<div id="templatemo_wrapper">
    <div id="templatemo_top">
        <div id="templatemo_login">
        <?include "loginbox.php"?>
        </div>
    </div> <!-- end of top -->

    <div id="templatemo_header">
        <div id="site_title"><h1><a href="http://www.spaladonna.com">SPA LaDonna</a></h1></div>
        <div id="templatemo_menu" class="ddsmoothmenu">
            <? include "mainmenu.php" ?>
        </div> <!-- end of templatemo_menu -->
    </div> <!-- end of header -->
    <? include "checkuser.php"?>
    <div id="templatemo_main">
        <div id="templatemo_content">
            <div class="col_fw">
                <h1>Register User</h1>

                <fieldset>
                    <legend>New User Signup</legend>
                    <form method="post">
                        <ul>

                                <li><label for="username">Username</label>
                                <input type="text" id="username" size="30" onblur="checkUser()" />
                                <div id=user >   </div>
                                </li>

                                <li><label for="email">Email</label>
                                <input type="text" name="email" id="email" size="30" />
                                </li>

                                <li><label for="first_name">First Name</label>
                                <input type="text" name="first_name" id="first_name" size="30" />
                                </li>

                                <li><label for="last_name">Last Name</label>
                                <input type="text" name="last_name" id="last_name" size="30" />
                                </li>

                                <li><label for="cell">Cell</label>
                                <input type="text" name="cell" id="cell" size="30" />
                                </li>

                                <li><label for="street">Street</label>
                                <input type="text" name="street" id="street" size="30" />
                                </li>

                                <li><label for=city">City</label>
                                <input type="text" name="city" id="city" size="30" />
                                </li>

                                <li><label for="zip">Zip</label>
                                <input type="text" name="zip" id="zip" size="30" />
                                </li>

                                <li><label for="password">Password</label>
                                <input type="password" name="password" id="password" size="30" />
                                </li>

                                <li><label for="password2">Repeat Password</label>
                                <input type="password" name="password2" id="password2" size="30" />
                                </li>

                                <li><label for="submit"></label>
                                <button type="submit" name="submit" id="submit">Register</button>
                                </li>

                        <ul>
                    </form>
                </fieldset>
<script type="text/javascript">
var request=null;
function createRequest()
{
    try{

        request= new XMLHttpRequest();

        }catch(tryMicrosft){
            try{
                request= new ActiveXObject("Msxml2.XMLHTTP");

            }catch(otherMicrosoft){
                try{

                        request=new ActiveXObject("Microsoft.XMLHTTP");
                }catch(failed){

                    request=null;
                }
            }   
        }
        if(request==null)
        alert("Error creating request object!");
//else alert("Successfully created");
}

function checkUser()
{   
    var userID=document.getElementById('username').value;
    alert(userID);
    createRequest();
    var url= "userCheck.php?username="+userID;
    //alert(url);
    request.open("GET",url,true);
    request.onreadystatechange=updatePage;
    request.send(null);
}
function updatePage()
{
    if(request.readyState==4)
    replaceText('user',request.responseText);
}

function clearText(el) {
  if (el != null) {
    if (el.childNodes) {
      for (var i = 0; i < el.childNodes.length; i++) {
        var childNode = el.childNodes[i];
        el.removeChild(childNode);
      }
    }
  }
}


function replaceText(el, text) {
  if (el != null) {
    el=document.getElementById(el);
    clearText(el);
   //setTimeout("alert("HELLO")", 4000);


    var newNode = document.createTextNode(text);

   el.appendChild(newNode);




  }
}

</script>
                </div>
<div class="col_fw_last">                 

                <div class="col_w300 float_l">

                </div>

                <div class="col_w300 float_r">

                </div>

                <div class="cleaner"></div>
            </div>  
        </div> <!-- end of content -->

        <div id="templatemo_sidebar">
        <h4>Categories</h4>
            <div class="sidebar_box">
                <ul class="templatemo_list">
                    <li><a href="#">Aliquam pretium porta odio</a></li>
                    <li><a href="#">Integer sit amet erat sit</a></li>
                    <li><a href="#">Nunc elementum mollis</a></li>
                    <li><a href="#">Quisque dictum pharetra</a></li>
                </ul>
            </div>

            <div class="cleaner h40"></div>

            <h4>Cool Links</h4>
            <div class="sidebar_box">
                <ul class="templatemo_list">
                    <li><a href="http://www.templatemo.com" target="_parent">Free CSS Templates</a></li> 
                    <li><a href="http://www.flashmo.com/page/1" target="_parent">Flash XML Galleries</a></li>
                    <li><a href="http://www.flashmo.com" target="_parent">Flash Templates</a></li>
                    <li><a href="http://www.webdesignmo.com/blog" target="_parent">Web Design Resources</a></li>
                </ul>
            </div>
            <div class="cleaner h40"></div>
                <h4>Latest Updates</h4>
                <div class="news_box">
                    <a href="#">Donec eu orci dolor</a>
                    <p>Pellentesque in nunc quam. Sed molestie ultricies ante, vel scelerisque diam varius sed. </p>
                </div>
                <div class="news_box">
                    <a href="#">Aliquam bibendum vulputate</a>
                    <p>Auris nisl mi, aliquet ac lobortis ut, tincidunt in tortor nisl vitae lectus dapibus pellentesque.</p>
                </div>
                <div class="news_box">
                    <a href="#">Nunc viverra vestibulum </a>
                    <p>Nunc viverra vestibulum magna, nec dignissim turpis rhoncus tincidunt. Donec ac nibh arcu. </p>
                </div>
                <div class="news_box">
                    <a href="#">Fusce placerat ultrices</a>
                    <p>Integer ac ultricies nisi. Curabitur velit ante, porttitor ac feugiat a, porta ut lectus.</p>
                </div>
        </div> <!-- end of sidebar -->

        <div class="cleaner"></div>
    </div> <!-- end of main -->
</div> <!-- end of wrapper -->

<div id="templatemo_footer_wrapper">
    <div id="templatemo_footer">
        Copyright © 2012 <a href="#"></a>
        <div class="cleaner"></div>
    </div>
</div> 

</body>
</html>
<? ob_flush(); ?>

登记处
函数明文(字段)
{
如果(field.defaultValue==field.value)field.value='';
如果(field.value='')field.value=field.defaultValue,则为else;
}
/***********************************************
*平滑导航菜单-(c)动态驱动器DHTML代码库(www.dynamicdrive.com)
*此通知必须保持完整,以便合法使用
*访问动态驱动http://www.dynamicdrive.com/ 获取完整的源代码
***********************************************/
ddsmoothmenu.init({
mainmenuid:“templatemo_菜单”//menu DIV id
方向:“h',//水平或垂直菜单:设置为“h”或“v”
classname:'ddsmoothmen',//已将类添加到菜单的外部DIV
//客户主题:[“1c5a80”、“18374a”],
contentsource:“标记”/“标记”或[“容器id”,“指向菜单文件的路径”]
})
注册用户
新用户注册
  • 用户名
  • 电子邮件
  • 名字
  • 细胞
  • 街头
  • 试试这个

    //replace
    
    var userID=document.getElementById('username').value;
    
    //for this
    
    var userID = document.forms[0]['username'].value;
    

    是的-所以这肯定是我的ID 10 T错误-我调用loginbox.php,没有意识到它将ID='username'设置为实际单词“username”作为占位符


    将表单上的一个更改为id='newuser'等-boom all is well

    什么不起作用?为什么你会期望警报值用引号括起来?我不会-我只是想解释那些引号并不存在-我试图从用户输入字段中获取数据,它一直说输入的数据就是我放在这把小提琴里的用户名:。我看不出有什么奇怪的地方——“value”应该是一个空字符串。这个值之所以会是“用户名”
,唯一的原因是如果你真的把“用户名”
写进了输入框。我当时不知道……不管我把什么放进框中,它都会返回“用户名”这个词。显然,这不是你的全部代码。发布更多,bug就会出现;)使用表单[0]时,我一点也没有数据。如果对我有用,请在表单上添加一个id,如下所示。不去-我肯定它的一些错误,在老鼠窝的代码lol-我要2重建它和c如何去
<? ob_start(); ?>
<?php 
session_start(); 
$_SESSION['url'] = $_SERVER['REQUEST_URI'];
if(isset($_POST['login'])){
        require_once "UserManagement.php";
        $usman=new UserManagement();
        if($usman->authenticate($_POST['username'],md5($_POST['password']))){
                header('Location: http://www.me.com')
        }else {
                echo "Authentication error";
                echo '<a href="index.php">Home</a>';            
        }
        die();
}
?>
//replace

var userID=document.getElementById('username').value;

//for this

var userID = document.forms[0]['username'].value;