CMellor Posted March 11, 2007 Share Posted March 11, 2007 Hello, I have been trying to develop a bit of code to allow me to update a database field when an onChange occures on a drop down box. For some odd reason, it doesn't work at all, also I might add I am using Prototype. Here's my code: <script language="Javascript" type="text/javascript"> // Update roster brand function changeBrand(value, id) { new Ajax.Updater('div', 'js/brand.php?show=' + value + '&id=' + id); } </script> <?php // MySQL connect include('../../include/functions.php'); // connect connect(); if(!isset($_GET['show'])) { mysql_query("UPDATE ibf_members SET mgroup = '".$_GET['show']."' WHERE id = '".$_GET['id']."'"); } // close MySQL mysql_close(); ?> echo(' <form action="" method="post" name="form"> <select name="brand" onchange="changeBrand(document.form.brand.options[document.form.brand.selectedIndex].value, '.$row['id'].'); return false"> '); // query $group_query = mysql_query("SELECT * FROM ibf_groups, ibf_members WHERE ibf_groups.g_id = ibf_members.id AND g_id IN(3, 4, 6, 7)"); // fetch data while($groups = mysql_fetch_array($group_query)) { $selected = $row['mgroup'] == $groups['g_id'] ? 'selected' : ''; echo(' <option value="'.$groups['g_id'].'" '.$selected.'>'.$groups['g_title'].'</option> '); } echo(' </select> </form> <div id="div"></div> '); Does anything look wrong? Quote Link to comment https://forums.phpfreaks.com/topic/42263-ajaxphp-and-drop-down-menus/ Share on other sites More sharing options...
ober Posted March 12, 2007 Share Posted March 12, 2007 2 things: Try changing it to onChange (capital C) Or try using a different event. You're also not checking the result of the SQL for a valid result (nor are you cleaning the input). That's never good. Are you getting any JS errors otherwise? Quote Link to comment https://forums.phpfreaks.com/topic/42263-ajaxphp-and-drop-down-menus/#findComment-205707 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.