homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Javascript in Firefox - not working?

10+ Year Member

Msg#: 3619513 posted 9:21 pm on Apr 4, 2008 (gmt 0)

Hi guys,

Any ideas as to why this script wont populate the textarea when using Firefox?

<tr><td><br /></td></tr>

<script type="text/javascript">
var sfsIndex = new Object;
sfsIndex.populated = false;
Typing a name into the suburb entry field will scroll the suburb select
field to a matching suburb name (if any).
function sfsComplete () {
if (!document.getElementById) return;
var text = document.getElementById('tb');
var select = document.getElementById('u');
if (!sfsIndex.populated) sfsBuildIndex();
var suburb = text.value.match(/,*([^,]+)$/);
if (suburb) {
var name = suburb[1].toUpperCase().replace(/^\s*/, '').replace(/\s*$/, '');
for (var i = sfsIndex[name.charAt(0)]; i < select.options.length; i++) {
if (select.options[i].text.toUpperCase().indexOf(name) == 0) {
select.selectedIndex = i;
else {
select.selectedIndex = -1;
On click event for the suburb select box. When clicked it populates
the suburb entry field then deselects the clicked suburb. Focus is
returned to the suburb entry field.
function sfsInsert () {
if (!document.getElementById) return false;
var text = document.getElementById('tb');
var select = document.getElementById('u');
// An IE bug means we need another event before select.selectedIndex
// will update from -1. Since we need to swap the focus anyway we'll
// do it before we look at what was clicked in the select box.
var suburb = select.options[select.selectedIndex];

// short circuit on 'show all suburbs'
if (select.selectedIndex == 0) {
text.value = '';
return true;

// see if the selected suburb is in the list already
var textSuburbs = text.value.split(/\s*,\s*/);
if (!textSuburbs) return false;
var pattern = new RegExp('\s*' + suburb.text + '\s*$');
for (var i = 0; i < textSuburbs.length; i++) {
// if it's in the list don't do anything
if (pattern.exec(textSuburbs[i])) return false;
// its not in the list so lets add it replacing any incomplete words
var newvalue = text.value.replace(


"$1 " + suburb.text + "\n"

text.value = newvalue;
return false;
Builds an index based on the first occurrence of suburb starting with a
letter. This speeds up the 'for' search of the select because we can
then skip straight to suburbs starting with that letter.
function sfsBuildIndex () {
if (!document.getElementById) return;
var select = document.getElementById('u');
for (var i = select.options.length; i--;) {
sfsIndex[select.options[i].text.toUpperCase().charAt(0)] = i;
sfsIndex.populated = true;


<span class="brown3">Products:</span><br />

<span class="brown3"><strong></strong> select your products from the list:</span><br>
<br />
<select id="u" name="u" size="8" class="suburbsList" onclick="javascript:sfsInsert();">
<option selected="selected" value="">*** Show ALL Products ***</option>


// Get details from config file

// include database file

// connect to the database
$cid = mysql_connect($host,$username,$dbpass);
if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); }

// Autofill dropdown list 'select' with options from DB
$query = mysql_query("SELECT product_id, product_code, product_name, price FROM Products ORDER BY product_name");
while($r = mysql_fetch_assoc($query))
echo '<option value="'.$r['product_id'].'/'.$r['product_code'].' '.$r['product_name'].' : $'.$r['price'].'">'.$r['product_name'].' : $'.$r['price'].'</option>';


<br />

<textarea cols="30" name="tb" rows="6" class="enterSuburb" tabindex="1" autocomplete="off" onkeyup="javascript:sfsComplete();"></textarea>




5+ Year Member

Msg#: 3619513 posted 9:53 pm on Apr 4, 2008 (gmt 0)

to <textarea>

10+ Year Member

Msg#: 3619513 posted 10:47 pm on Apr 4, 2008 (gmt 0)

thank you!
You are a life saver :)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved