Jump to content

showuser not defined???


Greaser9780

Recommended Posts

Here is my select box that calls the js:

<html>

<head>

<script src="selectuser.js"></script>

</head>

<body>

<form>

<select name="users" onchange="showUser(this.value)">

<option>QB</option>

<option>WR</option>

<option>RB</option>

<option>TE</option>

<option>PK</option>

<option>DF</option>

</select>

</FORM>

<div id="txtHint"> </div>

</BODY>

</html>

 

Here is the java:

var xmlHttpfunction ;showUser(str)

{

xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)

{

alert ("Browser does not support HTTP Request")

 

}

var url="getuser.php"

url=url+"?q="+str

url=url+"&sid="+Math.random()

xmlHttp.onreadystatechange=stateChanged

xmlHttp.open("GET",url,true)

xmlHttp.send(null)

}

 

function stateChanged()

{

if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")

{

document.getElementById("txtHint").innerHTML=xmlHttp.responseText

}

}function GetXmlHttpObject()

{

var xmlHttp=null;

try

{

// Firefox, Opera 8.0+, Safari

xmlHttp=new XMLHttpRequest();

}

catch (e)

{

//Internet Explorer

try

  {

  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

  }

catch (e)

  {

  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

  }

}

return xmlHttp;

}

 

 

 

Here is what it is supposed to show:

<?php

$q=$_GET["q"];

require("db.php");

 

$sql="SELECT * FROM players WHERE position = '".$q."'";

 

$result = mysql_query($sql);

?>

<html>

<head>

</head>

<body>

<form action="select.php" method="post">

Team name:<input type='text' name='name'>

 

Password:<input type='password' name='pass'>

 

Comment:<input type='text' name='com' maxlength='80'>

 

<select name="playername">

<?php

while($row = mysql_fetch_array($result))

{

  echo "<option value='" . $row['name'] . "'>" . $row['name'] . "</option>";

 

  }

?>

</select>

<input type="submit" name="submit" value="select">

</form>

</body>

</html>

 

 

 

Any clues why I keep getting these errors

Link to comment
Share on other sites

Greaser9780,

 

I got it to work with the following files...

 

Try them out and let us know.

 

Scot L. Diddle, Richmond VA

 

 

 

test2.php

 


<html>
<head>
<style>

div#txtHint {
font-weight:bold;
}
</style>

<script src="/javascript/showUser.js"></script>
</head>
<body>
<form>
<select name="users" onchange="showUser(this.value)">
<option>QB</option>
<option>WR</option>
<option>RB</option>
<option>TE</option>
<option>PK</option>
<option>DF</option>
</select>
</FORM>
<div id="txtHint"> </div>
</BODY>
</html> 

 

 

showUser.js ( Called from test2.php,  it lives in a folder called javascript/ )

 


var xmlHttp

function showUser(str)
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
} 
var url="showUser.php"
url=url+"?"+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
document.getElementById("txtHint").innerHTML=xmlHttp.responseText 
} 
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
}
return xmlHttp;
}

 

 

showUser.php ( Called form showUser.js  ...  modified, because I don't have your DB definitions... )

 


<?php
$q=$_GET["q"];

// echo "\$q : " . $q;	

$con = mysql_connect('localhost', 'root', '');
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
 }

mysql_select_db("MySQL", $con);

$sql="SELECT * FROM user ";

$result = mysql_query($sql);

?>
<html>
<head>
</head>
<body>
<form action="select.php" method="post">
Team name:<input type='text' name='name'>

Password:<input type='password' name='pass'>

Comment:<input type='text' name='com' maxlength='80'>

<select name="playername">
<?php
while($row = mysql_fetch_array($result))
{
  echo "<option value='" . $row['0'] . "'>" . $row['1'] . "</option>";

  }
?>
</select>
<input type="submit" name="submit" value="select">
</form>
</body>
</html>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.