Splitting data from MySQL using PHP & Javascript works in IE but not in FF -
i have following javascript function on page:
function setfields(){ var menu = document.getelementbyid('editlocation'); var itemdataarray = menu[menu.selectedindex].value.split('|'); form.locationshortname.value = itemdataarray[0]; form.locationlongname.value = itemdataarray[1]; form.phone.value = itemdataarray[2]; form.address1.value = itemdataarray[3]; form.citystatezip.value = itemdataarray[4]; form.maplink.value = itemdataarray[5]; } down on form, have following:
<select class="input2" name="editlocation" id="editlocation" onchange = "setfields();"> <option value="-add new-"<?php if($editlocation=='-add new-'){echo(' selected="selected"');} ?>>-add new-</option> <?php require_once('connection.php'); $connection = mysql_connect($hostname,$username,$password) or die (mysql_errno().": ".mysql_error()."<br />"); mysql_select_db($database); $sql = "select * directions order dirshortname"; $query = mysql_query($sql); while ($row = mysql_fetch_array($query)) { echo('<option value="'.stripslashes($row['dirshortname']).'|'.stripslashes($row['dirlongname']).'|'.stripslashes($row['dirphone']).'|'.stripslashes($row['dirstreet']).'|'.stripslashes($row['dircsz']).'|'.stripslashes($row['dirmaplink']).'"'); if ($editlocation==stripslashes($row['dirshortname'])) { echo(' selected="selected"'); } echo('>'.stripslashes($row['dirshortname']).'</option>'); } ?> in essence, php supposed pack data elements pulled mysql option value portion of select box. once user selects record, javascript pulls packed data apart , populates other data elements on form. works wonderfully in ie, in ff fields not populate data.
the form long, i'll include anyway sake of completeness.
<form action="admin-dirs.php" method="post" enctype="multipart/form-data" style="margin:0px; padding:0px " id="form"> <table width="587" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="60"> </td> <td width="185">select location edit: </td> <td width="342"><select class="input2" name="editlocation" id="editlocation" onchange = "setfields();"> <option value="-add new-"<?php if($editlocation=='-add new-'){echo(' selected="selected"');} ?>>-add new-</option> <?php require_once('connection.php'); $connection = mysql_connect($hostname,$username,$password) or die (mysql_errno().": ".mysql_error()."<br />"); mysql_select_db($database); $sql = "select * directions order dirshortname"; $query = mysql_query($sql); while ($row = mysql_fetch_array($query)) { echo('<option value="'.stripslashes($row['dirshortname']).'|'.stripslashes($row['dirlongname']).'|'.stripslashes($row['dirphone']).'|'.stripslashes($row['dirstreet']).'|'.stripslashes($row['dircsz']).'|'.stripslashes($row['dirmaplink']).'"'); if ($editlocation==stripslashes($row['dirshortname'])) { echo(' selected="selected"'); } echo('>'.stripslashes($row['dirshortname']).'</option>'); } ?> </select></td> </tr> <tr> <td width="60"> </td> <td colspan="2"><span class="main" style=" padding-left:12px; padding-right:12px; padding-top:6px"><br /> (note: leaving long name blank duplicate short name.)</span></td> </tr> <?php if(!$errlocationshortname=='' ){echo(' <tr> <td width="60"> </td> <td width="185"> </td> <td width="342"><span class="redtxterror">'.$errlocationshortname.'</span></td> </tr>');} ?> <tr> <td> </td> <td>location short name: <span class="red_star">*</span> </td> <td><input name="locationshortname" id="locationshortname" type="text" class="input2<?php if(!$errlocationshortname==''){echo('r');} ?>" value="<?php echo($locationshortname); ?>" maxlength="50"></td> </tr> <?php if(!$errlocationlongname=='' ){echo(' <tr> <td width="60"> </td> <td width="185"> </td> <td width="342"><span class="redtxterror">'.$errlocationlongname.'</span></td> </tr>');} ?> <tr> <td> </td> <td>location long name: <span class="red_star">*</span> </td> <td><input name="locationlongname" id="locationlongname" type="text" class="input2<?php if(!$errlocationlongname==''){echo('r');} ?>" value="<?php echo($locationlongname); ?>" maxlength="50"></td> </tr> <?php if(!$erraddress=='' ){echo(' <tr> <td width="60"> </td> <td width="185"> </td> <td width="342"><span class="redtxterror">'.$erraddress.'</span></td> </tr>');} ?> <tr> <td> </td> <td>street address: <span class="red_star">*</span> </td> <td><input name="address1" id="address1" type="text" class="input2<?php if(!$erraddress==''){echo('r');} ?>" value="<?php echo($address); ?>"></td> </tr> <?php if(!$errcsz=='' ){echo(' <tr> <td width="60"> </td> <td width="185"> </td> <td width="342"><span class="redtxterror">'.$errcsz.'</span></td> </tr>');} ?> <tr> <td> </td> <td>city, state, zip: <span class="red_star">*</span> </td> <td><input name="citystatezip" id="citystatezip" type="text" class="input2<?php if(!$errcsz==''){echo('r');} ?>" value="<?php echo($csz); ?>"></td> </tr> <?php if(!$errphone=='' ){echo(' <tr> <td width="60"> </td> <td width="185"> </td> <td width="342"><span class="redtxterror">'.$errphone.'</span></td> </tr>');} ?> <tr> <td> </td> <td>location phone number: <span class="red_star">*</span> </td> <td><input name="phone" id="phone" type="text" class="input2<?php if(!$errphone==''){echo('r');} ?>" value="<?php echo($phone); ?>" maxlength="20"></td> </tr> <?php if(!$errmaplink=='' ){echo(' <tr> <td width="60"> </td> <td width="185"> </td> <td width="342"><span class="redtxterror">'.$errmaplink.'</span></td> </tr>');} ?> <tr> <td> </td> <td>paste link map: <span class="red_star">*</span> </td> <td><input name="maplink" id="maplink" type="text" class="input2<?php if(!$errmaplink==''){echo('r');} ?>" value="<?php echo($maplink); ?>" maxlength="125"></td> </tr> <tr> <td> </td> <td> </td> <td><div align="right" style="padding-right:25px"> <input type="hidden" id="action" name="action" value="submitform" /> <input type="submit" id="savenew" name="savenew" value="save & new" /> <input type="submit" id="submit" name="submit" value="save & close" /> <?php if(!isset($_post['action'])) {?> <input type="reset" id="reset" name="reset" value="reset" /> <?php } ?> </div></td> </tr><tr> <td> </td> <td> </td> <td class="main_d"><div align="right" style="padding-right:25px">your ip address logged as: <?php echo($ip); ?></div></td> </tr> </table> </form>
- have checked ff's javascript console (shift-ctrl-j) errors?
- have tried using javascript debugger (like ff's firebug) see
menu,itemdataarrayvalues after set them?
i'm guessing you'll "form not object" or that. ie has wonderful annoying side effect of auto-creating objects tags , tag id's. you're not defining "form" inside setfields() function, ff no doubt complain form variable doesn't exist. in ie, since auto-creates stuff whenever wants, created 'form' you, ff won't, it's not working.
Comments
Post a Comment