...

View Full Version : Not Showing Integer



CoolAsCarlito
10-22-2008, 02:15 AM
I changed some things and am doing this for someone else as well for his site. I have the shownames showing correctly in the dropdown however it's not putting the integer into the readonly input field. Anyone know why?


Here's my form:


<?php
print '<form action="setupshow.php" method="post" name="myForm">';
print '<tr><td>Show Name:</td><td><select name="showname" id=\"names\" onChange="ajaxGet();"><option value="">Select a Name</option>';
$query = 'SELECT showname FROM shownames ORDER BY showname';
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result))
{
print "<option value=\"{$row['showname']}\">{$row['showname']}</option>\r";
}
print '</select></td></tr>';
print '<tr><td>Show Label:</td><td><input name="showlabel" id="label" type="text" readonly="true" size="5"></td></tr>';
print '<tr><th colspan=2><input name="submit" type="submit" value="Submit"><input name="sumbitted" type="hidden" value="TRUE"></th></tr></table></form>';
?>



Here's my javascript code:


<script type="text/javascript">
function ajaxGet()

{

var xmlHttp;

try

{

// Firefox, Opera 8.0+, Safari

xmlHttp=new XMLHttpRequest();

}

catch (e)

{

// Internet Explorer

try

{

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

}

catch (e)

{

try

{

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

}

catch (e)

{

alert("Your browser does not support AJAX!");

return false;

}

}

}

xmlHttp.onreadystatechange=function()

{

if(xmlHttp.readyState==4)

{

document.getElementById('shownam').innerHTML = xmlHttp.responseText;
ajaxGetL();

}

}

//alert("Selected: " + document.getElementById("ajax1").value);

xmlHttp.open("GET","showAjax.php?type=" + document.getElementById("ajax1").value + "&rand=" + Math.random(),true);

xmlHttp.send(null);

}

function ajaxGetL()

{
//alert("CALLED");
var xmlHttp;

try

{

// Firefox, Opera 8.0+, Safari

xmlHttp=new XMLHttpRequest();

}

catch (e)

{

// Internet Explorer

try

{

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

}

catch (e)

{

try

{

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

}

catch (e)

{

alert("Your browser does not support AJAX!");

return false;

}

}

}

xmlHttp.onreadystatechange=function()

{

if(xmlHttp.readyState==4)

{

document.getElementById('label').value = xmlHttp.responseText;

}

}

//alert("Selected: " + document.getElementById("ajax1").value);

xmlHttp.open("GET","showAjax.php?label=" + document.getElementById("names").value + "&rand=" + Math.random(),true);

xmlHttp.send(null);
}
</script>



Here's my ajax page:

<?php

require('database.php');

if(isset($_GET['label']))
{
$label = mysql_real_escape_string($_GET['label'],$link);

$res = mysql_query("SELECT `showlabel` FROM `shownames` WHERE `showname` = '".$label."' ORDER BY `showlabel` DESC LIMIT 1;") or die("ERROR 1");

$list = mysql_fetch_assoc($res);

echo $list['showlabel']+1;
}

?>

mcjwb
10-22-2008, 03:19 PM
I think the problem lies in that you're not getting the selected "Show Name" properly. The line:

xmlHttp.open("GET","showAjax.php?label=" + document.getElementById("names").value + "&rand=" + Math.random(),true);
should be something like:

var names = document.getElementById("names");
xmlHttp.open("GET","showAjax.php?label=" + names.options[names.selectedIndex].value + "&rand=" + Math.random(),true);


Also your ajax function calls a second ajax function, which I don't think is necessary, but perhapsyou haven't shown us all the code or was it just for testing?

CoolAsCarlito
10-22-2008, 11:45 PM
That didn't work.

mcjwb
10-23-2008, 12:13 AM
On closer inspection of your code you appear to have some unwanted backslashes, so you may also want to change this line:


print '<tr><td>Show Name:</td><td><select name="showname" id=\"names\" onChange="ajaxGet();"><option value="">Select a Name</option>';

to this:


print '<tr><td>Show Name:</td><td><select name="showname" id="names" onChange="ajaxGet();"><option value="">Select a Name</option>';


Also, in your javascript you are trying to access some html elements that you haven't created(at least in the code you posted), such as; "ajax1" and "shownam".



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum