Page 1 of 2
Select Field Won't Insert Name Into Text Box
Posted: Tue Aug 05, 2008 1:52 pm
by CoolAsCarlito
I can't get the select field to insert in the title name when you select a title and I don't know why it won't.
Code: Select all
<html>
<head>
<script src="selectitle.js"></script>
</head>
<?php
// Connects to your Database
$link = mysql_connect("?", "?", "?") or die(mysql_error());
mysql_select_db("?",$link) or die(mysql_error());
if (!mysql_select_db("?", $link)) {
echo 'Could not select database';
exit;
}
?>
<center><table><tr><td>Title:</td><td>
<?php
echo '<select onchange="showTitle(this.value)">';
$data = mysql_query("SELECT titlename FROM titles");
while($row = mysql_fetch_assoc($data)) {
echo '<option value="'.$row['titlename'].'">'.$row['titlename'].'</option>';
}
echo '</select>';
?></td></tr></table></center>
<?php
$q=$_GET["q"];
// Connects to your Database
$link = mysql_connect("?", "?", "?") or die(mysql_error());
mysql_select_db("?",$link) or die(mysql_error());
if (!mysql_select_db("?", $link)) {
echo 'Could not select database';
exit;
}
$sql="SELECT * FROM titles WHERE id = '".$q."'";
$result = mysql_query($sql);
?>
<center><table border=1 cellpadding=5 cellspacing=0 width=350>
<font color="#CC0000"><h2><center>Edit a Title</h2></center></font>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<tr><td>Title Name:</td><td>
<input type="text" name="titlename" maxlength="60" value=" <?php echo $row['titlename']; ?>">
</td></tr>
</html>
Re: Select Field Won't Insert Name Into Text Box
Posted: Tue Aug 05, 2008 2:08 pm
by Chalks
you have references to:
showTitle()
and
selectitle.js
Where is the showTitle() function?
What is the selectitle.js file?
Easiest way to change the title with javascript is "document.title = 'Your title here';"
Re: Select Field Won't Insert Name Into Text Box
Posted: Tue Aug 05, 2008 2:11 pm
by CoolAsCarlito
Here is selecttitle.js file:
Code: Select all
var xmlHttp function showtitle(str){ xmlHttp=GetXmlHttpObject();if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } var url="edittitle.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){ 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;}
Re: Select Field Won't Insert Name Into Text Box
Posted: Tue Aug 05, 2008 2:26 pm
by Chalks
I don't see what this is referencing:
"document.getElementById("txtHint").innerHTML=xmlHttp.responseText;"
Where is the element with id "txtHint"?
Also, where specifically are you trying to place this information?
Re: Select Field Won't Insert Name Into Text Box
Posted: Tue Aug 05, 2008 2:29 pm
by CoolAsCarlito
Okay to summarize what I'm trying to do is when the admin selects a title in the select field it'll go to my database table and grab that info and will post it in the text fields. I'm just trying to get it to post the name for now and then I'll work on the other parts of it.
Re: Select Field Won't Insert Name Into Text Box
Posted: Tue Aug 05, 2008 2:45 pm
by Chalks
CoolAsCarlito wrote:Okay to summarize what I'm trying to do is when the admin selects a title in the select field it'll go to my database table and grab that info and will post it in the text fields. I'm just trying to get it to post the name for now and then I'll work on the other parts of it.
Here are a few things:
the variable $q _needs_ to be escaped. That's a serious security hole. look into using at the very least mysql_real_escape_string().
Second, you seem to be mixing ajax along with your regular scripting, and it's making things confusing. I can't really tell from looking at your script what is supposed to be happening when.
Finally, when the user selects a title, the js function showtitle() is called. This function changes the element labled "txtHint", but I don't see that element _anywhere_.
Re: Select Field Won't Insert Name Into Text Box
Posted: Tue Aug 05, 2008 2:48 pm
by CoolAsCarlito
Well as for the txtHint what I did was take what I found on this site:
http://w3schools.com/php/php_ajax_database.asp and didn't know what to change.
Re: Select Field Won't Insert Name Into Text Box
Posted: Tue Aug 05, 2008 3:01 pm
by Chalks
Try this:
Code: Select all
<html>
<head>
<script src="selectitle.js"></script>
</head>
<body>
<?php
// Connects to your Database
$link = mysql_connect("?", "?", "?") or die(mysql_error());
mysql_select_db("?",$link) or die(mysql_error());
if (!mysql_select_db("?", $link)) {
echo 'Could not select database';
exit;
}
?>
<center><table><tr><td>Title:</td><td>
<?php
echo '<select onchange="showTitle(this.value)">';
$data = mysql_query("SELECT titlename FROM titles");
while($row = mysql_fetch_assoc($data)) {
echo '<option value="'.$row['titlename'].'">'.$row['titlename'].'</option>';
}
echo '</select>';
?></td></tr></table></center>
<center><table border=1 cellpadding=5 cellspacing=0 width=350>
<font color="#CC0000"><h2><center>Edit a Title</h2></center></font>
<tr>
<td>Title Name:</td>
<td>
<form name="change" action="Your/Script/Location/FileName.php" method="post">
<input type="text" name="titlename" maxlength="60" value="" /><br />
<input type="submit" value="submit" />
</form>
</td>
</tr>
</table>
</body>
</html>
Additionaly, change the line
Code: Select all
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
to
Code: Select all
document.forms['change'].titlename.value = xmlHttp.responseText;
Re: Select Field Won't Insert Name Into Text Box
Posted: Tue Aug 05, 2008 3:09 pm
by CoolAsCarlito
It still isn't putting the titlename into the text field.
Find it now at kansasoutlawwrestling.com/edittitle3.php
Re: Select Field Won't Insert Name Into Text Box
Posted: Tue Aug 05, 2008 3:20 pm
by Chalks
change the onchange value to this:
Code: Select all
onchange="showtitle(this.options[this.selectedIndex].value)"
edit: showTitle. capitalize the T. Don't know if it matters, but might as well make sure it's exactly right.
Re: Select Field Won't Insert Name Into Text Box
Posted: Tue Aug 05, 2008 3:28 pm
by CoolAsCarlito
bummer for some reason it's just not working
Re: Select Field Won't Insert Name Into Text Box
Posted: Tue Aug 05, 2008 3:33 pm
by Chalks
selectitle.js isn't in that directory. It needs to be.
Re: Select Field Won't Insert Name Into Text Box
Posted: Tue Aug 05, 2008 3:44 pm
by CoolAsCarlito
What directory?
Re: Select Field Won't Insert Name Into Text Box
Posted: Tue Aug 05, 2008 3:47 pm
by Chalks
CoolAsCarlito wrote:What directory?
http://kansasoutlawwrestling.com/selectitle.js is a 404 error. However, edittitle3.php expects it to exist.
Alternatively, replace
Code: Select all
<script src="selectitle.js"></script>
with
Code: Select all
<script type="text/javascript">
//all your javascript code goes here.
</script>
Re: Select Field Won't Insert Name Into Text Box
Posted: Tue Aug 05, 2008 4:02 pm
by CoolAsCarlito