Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Integrating PHP and JavaScript

Status
Not open for further replies.

dodgyone

Technical User
Joined
Jan 26, 2001
Messages
431
Location
GB
My code is below. On changing the first drop-down box the second drop-down box is dynamically filled with the relevant data. The listings are generated through PHP linking to MySQL within the JavaScript code.

The problem is that I am using this form in order to search a MySQL database. The select field 'type' is not used correctly as a variable in the sql query on the results page. No results appear on screen when using the value in the 'type' select box. I have found that when I omit onChange="fillState(this.form); it can be correctly used. Ha anybody got a workaround for this? Thanks...

===========================================
===========================================

<html>
<head>
<title>Helpdesk</title>
<link rel="stylesheet" type="text/css" href="hdstyle.css">

<script language="Javascript">

function fillState(form) {
if (form.type.selectedIndex == "1") {
form.state.options.length = 0;
form.state.options[1] = new Option("SCFHNT5", "SCFHNT5");
form.state.options[2] = new Option("SCFHNT8", "SCFHNT8");
form.state.options[3] = new Option("SCFHNT9", "SCFHNT9");
}
else if (form.type.selectedIndex == "2") {
form.state.options.length = 0;
form.state.options[1] = new Option("Lime", "Lime");
form.state.options[2] = new Option("Orange", "Orange");
}
}
</script>
</head>

<body>
<div align="center">

<div align="center"><h1>ITU Network Changes</h1><OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="shockwave/cabs/flash/swflash.cab#version=4,0,2,0" width="843" height="47">
<PARAM name="movie" value="Starlight.swf">
<PARAM name="quality" value="high">
<PARAM name="menu" value="true">
<EMBED src="Starlight.swf" quality="high" menu="true" pluginspage="download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="843" height="47">
</EMBED>
</OBJECT></div>
<form action="search_id.php" method="post">
<table border="4"
bordercolorlight="#c6e7de"
bordercolordark="#31ada5"
>

<tr>
<td align="left">
<b>Unique Number </b><input type="text" name="id" size="10"></td>
&nbsp;
<td width="25%" align="left">
<input type="submit" name="submit" value="Submit"></td>
</tr>
</table>
</form>
<br>
<br>






<h3>Advanced Search</h3>
<form action="search_script.php" method="post">
<table border="3" bordercolorlight="#c6e7de" bordercolordark="#31ada5">
<tr>
<td width="121" height="35">Type</td>
<td width="180" height="35"> <select name="type" onChange="fillState(this.form);">
<option value="none">-- choose one --</option>
<option value="Server">Server</option>
<option value="Coms">Coms</option>
</select></td>
<td width="59" height="35">List</td>
<td height="35" colspan="3"> <select name="state">
<option value="none">-- choose one --</option>
</select> </td>
</tr>
<tr>
<td height="35">Assigned To</td>
<td height="35"> <select name="assignedto" size="1">
<option value="none">-- choose one --</option>
<option value="Jon Jehan">Jon Jehan</option>
<option value="Pierre Humphries">Pierre Humphries</option>
<option value="Neil Martin">Neil Martin</option>
<option value="John Fitzpatrick">John Fitzpatrick</option>
<option value="Kevin Austin">Kevin Austin</option>
<option value="Ian Maxey">Ian Maxey</option>
<option value="Mat Ewins">Mat Ewins</option>
<option value="Marcus Jehan">Marcus Jehan</option>
<option value="Chris Harvey">Chris Harvey</option>
<option value="Dan Le Poidevin">Dan Le Poidevin</option>
<option value="Richard Elliott">Richard Elliott</option>
<option value="Sam Holland">Sam Holland</option>
<option value="Wayne Robert">Wayne Robert</option>
<option value="Peter Doyle">Peter Doyle</option>
</select></td>
<td height="35">Status</td>
<td height="35"> <select name="status" size="1">
<option value="none">-- choose one --</option>
<option value="Request">Request</option>
<option value="Complete">Complete</option>
</select> </td>
<td height="35">Change Type</td>
<td height="35"> <select name="changetype" size="1">
<option value="none">-- choose one --</option>
<option value="System Configuration">System Configuration</option>
<option value="Update">Update</option>
</select> </td>
</tr>
<tr>
<td height="5" colspan="6"></td>
</tr>
<tr>
<td height="35" colspan="6">Notes</td>
</tr>
<tr>
<td colspan="6" align="center"><textarea name="notes" cols="75" rows="5"></textarea></td>
</tr>
<tr>
<td height="5" colspan="6"></td>
</tr>
<tr align="center">
<td height="40" colspan="6">
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Submit" value="Reset">
</td>
</tr>
</table>
</center>

</form>

</div>
</body>
</html>

===========================================
===========================================


================================
&quot;Chaos, panic & disorder - my work here is done!&quot;
================================
 
Insufficient data for a meaningful answer.

What are you doing with the value in the script this form submits to?



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Using the code:

if ($type!='none'){
$ty="type='$type'";
}
else {
$ty="type like '%%'";
}

There are other variables created in a similar way to this. Then an sql query is created and executed integrationg these newly created variables:

$query = "SELECT id, type, state, assignedto, status, changetype, notes, date_format(date, '%d/%m/%Y, %h:%i') AS Readable_Date FROM call
WHERE $ty AND $ss AND $as AND $st AND $ch AND $nts";

================================
&quot;Chaos, panic & disorder - my work here is done!&quot;
================================
 
In that case, it's probably your register_globals setting.

Don't reference $type. Reference $_POST['type'].



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Just a suggestion... but you might want to change the name of the form element from type to something else. It just seems awfully close to a reserved name (in Javascript) to be something I would be comfortable with.

Of course... the solution to your problem and my suggestion are most likey unrelated... I would pick that sleipnir214 hit the nail on the head for that one :)

Jeff
 
Neither of these solutions work. It does work however when the JavaScript onChange command is omitted:

onChange="fillState(this.form);

So, it must be the Javascript surely?

================================
&quot;Chaos, panic & disorder - my work here is done!&quot;
================================
 
Found what was wrong... my if, else, else if statement was incorrect in another part of the PHP code.

Thanks for trying to help guys...

================================
&quot;Chaos, panic & disorder - my work here is done!&quot;
================================
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top