Click to See Complete Forum and Search --> : javascript with php explode? - Please help


sgtpepper
08-08-2003, 09:54 AM
I am trying to get this piece of javacode to place the results from list2 into a variable called selecttown[]

Everytime I do, I break the java...I am still learning...so I am wondering if you can help me get this to work...


<?
session_start();
session_unset();
session_register("selecttown");
session_register("bedroomsel");
session_register("bathselect");
session_register("lowprice");
session_register("highprice");
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
?>
<script>

var isNS4 = (navigator.appName=="Netscape")?1:0;

</script>
<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
function move(fbox, tbox) {
var arrFbox = new Array();
var arrTbox = new Array();
var arrLookup = new Array();
var i;
for (i = 0; i < tbox.options.length; i++) {
arrLookup[tbox.options[i].text] = tbox.options[i].value;
arrTbox[i] = tbox.options[i].text;
}
var fLength = 0;
var tLength = arrTbox.length;
for(i = 0; i < fbox.options.length; i++) {
arrLookup[fbox.options[i].text] = fbox.options[i].value;
if (fbox.options[i].selected && fbox.options[i].value != "") {
arrTbox[tLength] = fbox.options[i].text;
tLength++;
}
else {
arrFbox[fLength] = fbox.options[i].text;
fLength++;
}
}
arrFbox.sort();
arrTbox.sort();
fbox.length = 0;
tbox.length = 0;
var c;
for(c = 0; c < arrFbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrFbox[c]];
no.text = arrFbox[c];
fbox[c] = no;
}
for(c = 0; c < arrTbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrTbox[c]];
no.text = arrTbox[c];
tbox[c] = no;
}
}
// End -->
</script>

<?php
include("../includes/resheader.php");
?>
<p>
<center>
Use our search form below to enter information on the type of property you are looking for, and click on 'submit'.<br>
We
will search our database and display the results of your search in just a few seconds.
<form action="maincode.php" method="POST">
<table border="0" width="63%" bgcolor="#FEF5ED">
<tr>
<td width="100%">
<table border="0" width="100%">

<tr>
<td width="20%" bgcolor="#003366" align="center"><strong><font color="#FFFFFF" face="Tahoma" size="2">Town</font></strong></td>
<td width="20%" bgcolor="#003366" align="center"><strong>
<font color="#FFFFFF" face="Tahoma" size="2">Price Range</font></strong></td>
<td width="20%" bgcolor="#003366" align="center"><strong>
<font color="#FFFFFF" face="Tahoma" size="2">Bed Rooms</font></strong></td>
<td width="20%" bgcolor="#003366" align="center"><strong>
<font color="#FFFFFF" face="Tahoma" size="2">Baths Rooms</font></strong></td>
</tr>
<tr>
<td width="20%">

<table><tr><td>
<select multiple size="10" name="list1" style="width:150">
<option value="Lyme NH">Lyme, NH</option>
<option value="Hanover NH">Hanover, NH</option>
<option value="Lebanon NH">Lebanon, NH</option>
<option value="Plainfield NH">Plainfield, NH</option>
<option value="Enfield NH">Enfield, NH</option>
<option value="Canaan NH">Canaan, NH</option>
<option value="Grafton NH">Grafton, NH</option>
<option value="Grantham NH">Grantham, NH</option>
<option value="Eastman NH">Eastman, NH</option>

</select>
</td>
<td align="center" valign="middle">
<input type="button" onClick="move(this.form.list2,this.form.list1)" value="<<">
<input type="button" onClick="move(this.form.list1,this.form.list2)" value=">>"></td>
<td>
<select multiple size="10" name="list2" style="width:150">
</select>
</td></tr></table>

</td>
<td width="20%">
Enter your lowest price
$<input type="text" name="lowprice" size="20" value="0">
Enter your highest price
$<input type="text" name="highprice" size="20" value="300000">
</select>

</td>
<td width="20%">

<input type="radio" value="%" name="bedroomsel" checked><font face="Courier">Any<br>
<input type="radio" value="1" name="bedroomsel"">1<br>
<input type="radio" value="2" name="bedroomsel"">2<br>
<input type="radio" value="3" name="bedroomsel"">3</font></td>
<td width="20%">
<input type="radio" value="%" name="bathselect" checked><font face="Courier">Any<br>
<input type="radio" value="1" name="bathselect">1<br>
<input type="radio" value="2" name="bathselect">2</font></td>

</tr>
</table>
<p align="center"><input type="submit"><input type="reset"></p>
</form>
</td>
</tr>
</table>
</form>
</center>
<p>
<?php
include("footer.php");
?>


Again, the goal is to make my results for list2 become selecttown[]

Phil Karras
08-08-2003, 10:53 AM
The only place I see "selecttown" is in the PHP section:

<?
session_start();
session_unset();
session_register("selecttown");
session_register("bedroomsel");
session_register("bathselect");
session_register("lowprice");
session_register("highprice");
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
?>


As far as I know then there is no JavaScript var called selecttown, QED you can't get there from here.

To place a form-field value into another var you use:

var selecttown = document.form.list2.value;

<!-- with the name of the fome = 'form' -->
<form name='form' action="maincode.php" method="POST">

If the form is not named you use:

var selecttown = document.forms[0].list2.value;

assuming this is the first form in the forms[] array.