boo_lolly Posted April 25, 2007 Share Posted April 25, 2007 Sorry Benjaminbeazy, Can you guide me little more, please. you are wanting a dropdown menu to have a 'pre-selected' feature to display to the user. in order to do this, we have to know what the choice the user submitted. this data can be retrieved by accessing the $_POST array. particularly, the name of the input field, like this: $_POST['Combo2']. so you use this value and compare it to a string, 'Yes' or 'No'. if the data in $_POST['Combo2'] matches either one of those, it will add ' SELECTED' to the input field, making it 'pre-selected'. as illustrated in the code below: <?php echo " <select name=\"Combo2\" size=\"1\" class=\"WorkPageField\" id=\"Combo2\"> <option value=\"Yes\"". (($_POST['Combo2'] == 'Yes') ? (' SELECTED') : ('') .">Yes <option value=\"No\"". (($_POST['Combo2'] == 'No') ? (' SELECTED') : ('') .">No </select> "; ?> Link to comment https://forums.phpfreaks.com/topic/48431-solved-can-any-one-help-me-in-%E2%80%9Clistbox%E2%80%9D/page/2/#findComment-237836 Share on other sites More sharing options...
oceans Posted April 25, 2007 Author Share Posted April 25, 2007 Dear Benjaminbeazy, I am very touched you are trying your best, but it is not workin for me. Dear Boo_lolly, I am embaressed to say I do not know where to place your code into mine, can you please place it for me, please take the code Benjaminbeazy last posted, thanks. Link to comment https://forums.phpfreaks.com/topic/48431-solved-can-any-one-help-me-in-%E2%80%9Clistbox%E2%80%9D/page/2/#findComment-237844 Share on other sites More sharing options...
boo_lolly Posted April 25, 2007 Share Posted April 25, 2007 in your form, you have the data being submitted to 'Untitled-1.php'. that is the page where you can retrieve the $_POSTed data. is Untitled-1.php the same page, or a different page? Link to comment https://forums.phpfreaks.com/topic/48431-solved-can-any-one-help-me-in-%E2%80%9Clistbox%E2%80%9D/page/2/#findComment-237847 Share on other sites More sharing options...
oceans Posted April 25, 2007 Author Share Posted April 25, 2007 User Field Data posted onto itself. After processing then I will redirect to next page (after validation). Thus in our example, data submitted onto the same page Link to comment https://forums.phpfreaks.com/topic/48431-solved-can-any-one-help-me-in-%E2%80%9Clistbox%E2%80%9D/page/2/#findComment-237849 Share on other sites More sharing options...
benjaminbeazy Posted April 25, 2007 Share Posted April 25, 2007 using the last code i gave you, what errors come up? or what is not working? it works perfectly for me... Link to comment https://forums.phpfreaks.com/topic/48431-solved-can-any-one-help-me-in-%E2%80%9Clistbox%E2%80%9D/page/2/#findComment-237851 Share on other sites More sharing options...
oceans Posted April 25, 2007 Author Share Posted April 25, 2007 OK (1)the value does not stay at "No" though I choose "No" and push the button (2)the values found in the List box is >Yes & >No It should be Yes & No. Link to comment https://forums.phpfreaks.com/topic/48431-solved-can-any-one-help-me-in-%E2%80%9Clistbox%E2%80%9D/page/2/#findComment-237855 Share on other sites More sharing options...
benjaminbeazy Posted April 25, 2007 Share Posted April 25, 2007 ok can you try this one for me?? btw, aer you hosting this on your computer or is this on the web. if on the web, i'd like to see it <? ini_set('error_reporting',8191); ini_set('display_errors',1); ini_set('display_startup_errors',1); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <?PHP //Transfer Data from Screen to Memory $NumberOfTxtBoxes=5; $NumberOfTxtBoxesToBeFilled=5; if(isset($_POST['Submit'])){ $var1 = $_POST['var1']; $var2 = $_POST['var2']; for ($i=1; $i<=$NumberOfTxtBoxes; $i++) { $InputFromScreen[$i]=strtoupper($_POST["Txt".$i]); } } else { for ($i=1; $i<=$NumberOfTxtBoxes; $i++) { $InputFromScreen[$i]=""; } $var1 =""; $var2 =""; } ?> <form id="form1" name="form1" method="post" action=""> <table width="200" border="1"> <tr> <td> </td> <td><input name="Txt1" value="<?PHP echo $InputFromScreen[1]; ?>" type="text" id="Txt1" /></td> </tr> <tr> <td> </td> <td><input name="Txt2" value="<?PHP echo $InputFromScreen[2]; ?>" type="text" id="Txt2" /></td> </tr> <tr> <td> </td> <td><input name="Txt3" value="<?PHP echo $InputFromScreen[3]; ?>" type="text" id="Txt3" /></td> </tr> <tr> <td> </td> <td><input name="Txt4" value="<?PHP echo $InputFromScreen[4]; ?>" type="text" id="Txt4" /></td> </tr> <tr> <td> </td> <td><input name="Txt5" value="<?PHP echo $InputFromScreen[5]; ?>" type="text" id="Txt5" /></td> </tr> <tr> <td> </td> <td><select name="var2" size="1" class="WorkPageField" id="var2"> <option value="Yes" <?php if("Yes" == $var2){ echo "selected"; } ?>>Yes</option> <option value="No" <?php if("No" == $var2){ echo "selected"; } ?>>No</option> </select></td> </tr> <tr> <td> </td> <td><select name="var1" size="1" class="WorkPageField" id="var1"> <option value="Yes" <?php if("Yes" == $var1){ echo "selected"; } ?>>Yes</option> <option value="No" <?php if("No" == $var1){ echo "selected"; } ?>>No</option> </select></td> </tr> <tr> <td> </td> <td><?PHP ?></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Submit" /></td> </tr> </table> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/48431-solved-can-any-one-help-me-in-%E2%80%9Clistbox%E2%80%9D/page/2/#findComment-237862 Share on other sites More sharing options...
oceans Posted April 25, 2007 Author Share Posted April 25, 2007 Dear Friend, You have helped me twice today, this works. If you are near me I will buy you a drink, I am in Singapore, where are you? OK, I am working on my PC, I will settle my things at least 70% then I will hire server space if not I will be wasting money, I think no one want to give free server space for PHP MySQL right. ini.set sounds too technical, I hope once i finished i will not have problem in my production server. Link to comment https://forums.phpfreaks.com/topic/48431-solved-can-any-one-help-me-in-%E2%80%9Clistbox%E2%80%9D/page/2/#findComment-237877 Share on other sites More sharing options...
oceans Posted April 25, 2007 Author Share Posted April 25, 2007 Sorry I forgot the story, What you did last to get it to work. Link to comment https://forums.phpfreaks.com/topic/48431-solved-can-any-one-help-me-in-%E2%80%9Clistbox%E2%80%9D/page/2/#findComment-237878 Share on other sites More sharing options...
benjaminbeazy Posted April 25, 2007 Share Posted April 25, 2007 I AM THE WINNER!!!!!!!!!!!!!!!!!!!1111111111111 Link to comment https://forums.phpfreaks.com/topic/48431-solved-can-any-one-help-me-in-%E2%80%9Clistbox%E2%80%9D/page/2/#findComment-237882 Share on other sites More sharing options...
oceans Posted April 25, 2007 Author Share Posted April 25, 2007 Sorry the last one for the day, can you tell me what you did all appears similar to your last code, now this code works ok even if i remove all your "ini_set". Link to comment https://forums.phpfreaks.com/topic/48431-solved-can-any-one-help-me-in-%E2%80%9Clistbox%E2%80%9D/page/2/#findComment-237925 Share on other sites More sharing options...
benjaminbeazy Posted April 25, 2007 Share Posted April 25, 2007 changed my short tags to full tags, and changed ID txt33 to txt5 i think thats it, i ran it 30,000 times with all errors to see if there was a problem Link to comment https://forums.phpfreaks.com/topic/48431-solved-can-any-one-help-me-in-%E2%80%9Clistbox%E2%80%9D/page/2/#findComment-237926 Share on other sites More sharing options...
benjaminbeazy Posted April 25, 2007 Share Posted April 25, 2007 oh and i defined $var1 & 2 by default, even before the form has been posted. Link to comment https://forums.phpfreaks.com/topic/48431-solved-can-any-one-help-me-in-%E2%80%9Clistbox%E2%80%9D/page/2/#findComment-237928 Share on other sites More sharing options...
oceans Posted April 25, 2007 Author Share Posted April 25, 2007 Thanks Benjamin Link to comment https://forums.phpfreaks.com/topic/48431-solved-can-any-one-help-me-in-%E2%80%9Clistbox%E2%80%9D/page/2/#findComment-237930 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.