...

View Full Version : change javascript code to php



j-iN-uK
03-25-2004, 05:36 PM
Hi,

I'v been asked to change my javascript to php code. Please can u tel me how to change the javascript below to php. I am using some php. It's basically onclick of items in a listbox, I populate certain fields....

thanks


<?
echo "<TD rowspan=7 height=\"120\"><SELECT NAME=\"LstSchoolName\" ID=\"LstSchoolName\" SIZE=\"8\" ONCHANGE=\"Schoolselected(this);\" >
\n";

$sJavaScript = "function Schoolselected(elem)

{ for (var i = document.f1.length; i >= 0; i--)
{ document.f1.txtSchool.value[i] = null
document.f1.txtAddr.value[i] = null

$SName="";

while ( $row = mysql_fetch_array($result) )
{
If ($SName!=$row["SchoolName"]){

$SName = $row["SchoolName"];
echo "\n<OPTION VALUE='".$row["SchoolName"]."'>".$SName."</OPTION>
";

// and add a new section to the javascript...

$sJavaScript = $sJavaScript."}\n"."if (elem.options[elem.selectedIndex].value=='".$row["SchoolName"]."'){\n";

$sJavaScript = $sJavaScript."document.f1.txtSchool.value = ('".$row["SchoolName"]."');\n";
$sJavaScript = $sJavaScript."document.f1.txtAddr.value = ('".$row["Street"]."');\n";

$sJavaScript = $sJavaScript."if (document.f1.txtFundedBy.value == 'SCHOOL'){\n";
$sJavaScript = $sJavaScript."document.f1.txtAddr1.value = ('".$row["Street"]."');\n";
$sJavaScript = $sJavaScript."document.f1.txtName.value = ('".$row["SchoolName"]."')}\n";

}
}
$sJavaScript = $sJavaScript."\n}\n}\n";
echo "\n<SCRIPT LANGUAGE=\"JavaScript\">";
echo "\n".$sJavaScript."\n</SCRIPT>\n";
?>

Hawkmoon
04-01-2004, 03:55 AM
Hey J-in-uk,

The only way to have the PHP alter the value is to make the "onChange" equal submit() [onChange='submit()'] and then process the value using PHP and alter the other elements of the form.

-Hawkmoon

PS You would need to enclose the <SELECT> in <FORM>

raf
04-01-2004, 07:34 AM
http://www.codingforums.com/showthread.php?t=35809

Spookster
04-01-2004, 08:20 AM
Do not create multiple topics with the same question. All replies need to go in the thread that raf has listed which is your original thread.

Closing thread...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum