richrock Posted December 15, 2008 Share Posted December 15, 2008 Hi, I'm creating a form in which I need to do the following: I have a select box in which I have some sale categories. Some of these categories are 'locked', in other words, no more items should be added to that sale. I need to create an 'override' section to the form to expand if a locked sale is selected, without reloading the page (complications due to POST). Having no clue about ajax, and having trawled the web for the last couple of days, I need some help!! Here is the php code on which I need to base this: <tr> <td>Sale Number: <?php echo $rcatinfo; ?></td> <td> <select name="salenum"> <!--<option value='none'>-- Select A Sale --</option>--> <?php do { if ($rcatinfo==$row_selectsalenum['id']) { echo "<option value ='".$row_selectsalenum['id']."' selected>".$row_selectsalenum['id']." - ".$row_selectsalenum['catname']."</option>\n"; } else { echo "<option value ='".$row_selectsalenum['id']."'>".$row_selectsalenum['id']." - ".$row_selectsalenum['catname']."</option>\n"; } } while ($row_selectsalenum = mysql_fetch_assoc($resultsalenum)); $rows = mysql_num_rows($resultsalenum); if($rows > 0) { mysql_data_seek($resultname, 0); $row_selectsalenum = mysql_fetch_assoc($resultsalenum); } ?> </select> </td> </tr> I have set up a 'locked' column in the table and can add this to the select list, but am stuck as to how to proceed in order to create a form (which isn't a problem) if the category is locked... Any ideas would be appreciated. TIA Quote Link to comment https://forums.phpfreaks.com/topic/137013-solved-extend-form-using-ajax-based-on-select/ Share on other sites More sharing options...
xtopolis Posted December 16, 2008 Share Posted December 16, 2008 I'm having trouble understanding your problem. I get the jist, but I think you need to break it down. Also, and example/link to your site might help. First, you're saying simply that when someone selects a locked item from the select list, you want something to pop down near it, allowing an override? What type of thing needs to appear.. where.. etc? Secondly, depending how you want to do it, you could have the PHP output a custom attribute to the select if it is locked, and have javascript read that accordingly. Ex: <?php if($row['isLocked'] == 1){ echo '<option value="'.$row['id'].'" locked="true">'. //etc etc } ?> And then your <select > tag would have the onchange() function call javascript to see whether it needs to produce the additional form override.... Anything else, you'll have to be a lot more specific about what's not working, and what code you have, and why it's not working... Quote Link to comment https://forums.phpfreaks.com/topic/137013-solved-extend-form-using-ajax-based-on-select/#findComment-716427 Share on other sites More sharing options...
richrock Posted December 17, 2008 Author Share Posted December 17, 2008 Hi, Sorry for the delay in replying - caught a nice bout of flu over the weekend, so I'm a little behind on work First, you're saying simply that when someone selects a locked item from the select list, you want something to pop down near it, allowing an override? What type of thing needs to appear.. where.. etc? Exactly. I want a checkbox and a text input box. These will appear directly below the select, and I can separate the tables up if necessary. Unfortunately, the code is for a private adminisatration project, so it's not on the web as such. I just don't understand enough about Javascript to know how to make a form element 'appear'. Going back to your sample, I assume I am right in adding the 'locked' element like this: <tr> <td>Sale Number: <?php echo $rcatinfo; ?></td> <td> <select name="salenum" onchange="show.hiddenForm(locked)"> <!--<option value='none'>-- Select A Sale --</option>--> <?php do { if ($rcatinfo==$row_selectsalenum['id']) { echo "<option value ='".$row_selectsalenum['id']."' selected"; if($row['isLocked'] == 1){ echo 'locked="true"'. //etc etc } echo ">".$row_selectsalenum['id']." - ".$row_selectsalenum['catname']."</option>\n"; } else { echo "<option value ='".$row_selectsalenum['id']."'"; if($row['isLocked'] == 1){ echo 'locked="true"'. //etc etc } echo ">".$row_selectsalenum['id']." - ".$row_selectsalenum['catname']."</option>\n"; } } while ($row_selectsalenum = mysql_fetch_assoc($resultsalenum)); $rows = mysql_num_rows($resultsalenum); if($rows > 0) { mysql_data_seek($resultname, 0); $row_selectsalenum = mysql_fetch_assoc($resultsalenum); } ?> </select> </td> </tr> Yeah? Thanks for understanding. Quote Link to comment https://forums.phpfreaks.com/topic/137013-solved-extend-form-using-ajax-based-on-select/#findComment-717562 Share on other sites More sharing options...
richrock Posted December 17, 2008 Author Share Posted December 17, 2008 Right - got the select to show if the item is locked, now I've just gotta figure out how to show the form element when a locked sale is selected. I've made it a bit obvious at the moment to show which sale is locked... <?php // FIXME - add selection of option if sale locked. ?> <td>Sale Number: <?php echo $rcatinfo; ?></td> <td> <select name="salenum" onchange=""> <!--<option value='none'>-- Select A Sale --</option>--> <?php do { if ($rcatinfo==$row_selectsalenum['id']) { echo "<option value ='".$row_selectsalenum['id']."' selected>".$row_selectsalenum['id']." - ".$row_selectsalenum['catname']." - ".$row_selectsalenum['locked']; if ($row_selectsalenum['locked'] == 1) { echo "LOCKED"; } echo "</option>\n"; } else { echo "<option value ='".$row_selectsalenum['id']."'>".$row_selectsalenum['id']." - ".$row_selectsalenum['catname']." - ".$row_selectsalenum['locked']; if ($row_selectsalenum['locked'] == 1) { echo "LOCKED"; } echo "</option>\n"; } } while ($row_selectsalenum = mysql_fetch_assoc($resultsalenum)); $rows = mysql_num_rows($resultsalenum); if($rows > 0) { mysql_data_seek($resultname, 0); $row_selectsalenum = mysql_fetch_assoc($resultsalenum); } ?> </select> </td> </tr> <?php if ($sale_locked == 1) { echo "<tr><td colspan='2'>"; echo "<span style='color:#ff0000'>This sale has been sent to publication as a catalogue.</span>"; echo "</td></tr>"; echo "<tr><td>"; echo "Assigned Lot Number: "; echo "</td><td>"; echo "<input type='text' name='wibble' value='".$rlot_num."' readonly size='10' />"; echo "</td></tr>"; // FIXME - add feature for when adding the lots to consignment, if it's a locked sale. } ?> See also attached image for output. I'd like the extra form to appear directly below this select.... ??? Thanks [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/137013-solved-extend-form-using-ajax-based-on-select/#findComment-717603 Share on other sites More sharing options...
richrock Posted December 17, 2008 Author Share Posted December 17, 2008 solved it using Javascript from this page: http://www.quirksmode.org/dom/usableforms.html Thanks anyway. Quote Link to comment https://forums.phpfreaks.com/topic/137013-solved-extend-form-using-ajax-based-on-select/#findComment-717638 Share on other sites More sharing options...
xtopolis Posted December 17, 2008 Share Posted December 17, 2008 Cool, glad you got it to work. I would have helped more had I not been asleep :0 Quote Link to comment https://forums.phpfreaks.com/topic/137013-solved-extend-form-using-ajax-based-on-select/#findComment-717919 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.