neverett Posted January 15, 2008 Share Posted January 15, 2008 I'm having a bit of trouble working on a do-while loop for a prompt box. I'm looking for a sample piece of code that shows how you can require input on a prompt [using a do-while]. I really only need the conditions for the while portion. I keep making an infinite loop. So if they press cancel or if they type nothing [an empty string] then I want it to pop the prompt up again and again until they enter a string. Thank you for any help in advance. NE Quote Link to comment Share on other sites More sharing options...
taith Posted January 15, 2008 Share Posted January 15, 2008 do-whiles - in my book - are VERY VERY BAD... they are very easy to infinite loop and theres really no need... this should work FAR easier, and faster... <script> var blah=''; while(blah==''){ var blah=prompt('please enter your name'); } </script> Quote Link to comment Share on other sites More sharing options...
neverett Posted January 16, 2008 Author Share Posted January 16, 2008 Any ideas on how to get something like this to work? Post back if you have any questions. $details = ""; if($newstatus == 4){ $details = echo " <script type=\"text/javascript\"> var det = \"\"; while(det == \"\"){ det = prompt(\"Please detail the changes\", \"\"); } return det; </script> "; } This is the error I get... Parse error: parse error, unexpected T_ECHO in /home/content/t/r/a/tracpr/html/members/changestatus.php on line 16 Line 16 is: $details = echo " <script type=\"text/javascript\"> var det = \"\"; while(det == \"\"){ det = prompt(\"Please detail the changes\", \"\"); } return det; </script> "; Thanks in advance for any help you may have!!! NE Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted January 17, 2008 Share Posted January 17, 2008 try this and see if this corrects the error: <?php $details="";// you need to declare this and not just leave it empty if($newstatus == 4){ $details="<script type=\"text/javascript\"> var det = \"\"; while(det == \"\"){ det = prompt(\"Please detail the changes\", \"\"); } return det; </script>"; } echo "$details"; ?> Quote Link to comment Share on other sites More sharing options...
neverett Posted January 17, 2008 Author Share Posted January 17, 2008 Didn't work. Thanks though... I was really hopeful!! Quote Link to comment Share on other sites More sharing options...
neverett Posted January 25, 2008 Author Share Posted January 25, 2008 I found another way to implement. Thanks everyone. Quote Link to comment 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.