944,000 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1060
  • PHP RSS
Nov 6th, 2009
0

radio button validation

Expand Post »
we have two radio buttons with same name. when we check radiobutton no.of imagefile boxes appear.
for example i have two radio buttons. if i check 1 radio button appear 5 image upload fields. now selects another radio button selects then appear only 10 image upload field. anybody help.
Last edited by muralikalpana; Nov 6th, 2009 at 10:40 am.
Similar Threads
Reputation Points: 21
Solved Threads: 35
Posting Pro
muralikalpana is offline Offline
534 posts
since Sep 2009
Nov 6th, 2009
-1
Re: radio button validation
AM I correct in assuming you have:
2 radiobuttons - one to display 5 file upload fields and one to display 10 upload fields.

A quick and dirty solution would be to hide/show through javascript and css:

PHP Syntax (Toggle Plain Text)
  1. <input name="showups" type="radio" value="0" onclick="show_up(5);return false;" selected="selected" /><label for="show5">Show 5 upload fields</label>
  2. <input name="showups" id="show10" type="radio" value="1" onclick="show_up(10);return false;" /><label for="show10">Show 10 upload fields</label>
  3.  
  4. <input type="file" name="upload[]" />
  5. <input type="file" name="upload[]" />
  6. <input type="file" name="upload[]" />
  7. <input type="file" name="upload[]" />
  8. <input type="file" name="upload[]" />
  9. <div id = "extras" class="show">
  10. <input type="file" name="upload[]" />
  11. <input type="file" name="upload[]" />
  12. <input type="file" name="upload[]" />
  13. <input type="file" name="upload[]" />
  14. <input type="file" name="upload[]" />
  15. </div>

This gives an array of file elements (0 - 9).
In your head area:

PHP Syntax (Toggle Plain Text)
  1. <script>
  2. function show_up(x){
  3. if(x > 5){
  4. document.getElementById('extras').className = 'show';
  5. }else{
  6. document.getElementById('extras').className = 'hide';
  7. }
  8. }
  9. </script>
  10. <style>
  11. .hide{
  12. display:none;
  13. }
  14. </style>

If you fill file widgets in range 5-9 and then hide the last 5, they will still try to upload the files - so you could write something a bit "cleverer" to deal with this. This is just an example - I wouldn't use this in a production site.
Sponsor
Featured Poster
Reputation Points: 1054
Solved Threads: 949
Sarcastic Poster
ardav is offline Offline
6,700 posts
since Oct 2006
Nov 7th, 2009
0
Re: radio button validation
Click to Expand / Collapse  Quote originally posted by ardav ...
AM I correct in assuming you have:
2 radiobuttons - one to display 5 file upload fields and one to display 10 upload fields.

A quick and dirty solution would be to hide/show through javascript and css:

PHP Syntax (Toggle Plain Text)
  1. <input name="showups" type="radio" value="0" onclick="show_up(5);return false;" selected="selected" /><label for="show5">Show 5 upload fields</label>
  2. <input name="showups" id="show10" type="radio" value="1" onclick="show_up(10);return false;" /><label for="show10">Show 10 upload fields</label>
  3.  
  4. <input type="file" name="upload[]" />
  5. <input type="file" name="upload[]" />
  6. <input type="file" name="upload[]" />
  7. <input type="file" name="upload[]" />
  8. <input type="file" name="upload[]" />
  9. <div id = "extras" class="show">
  10. <input type="file" name="upload[]" />
  11. <input type="file" name="upload[]" />
  12. <input type="file" name="upload[]" />
  13. <input type="file" name="upload[]" />
  14. <input type="file" name="upload[]" />
  15. </div>

This gives an array of file elements (0 - 9).
In your head area:

PHP Syntax (Toggle Plain Text)
  1. <script>
  2. function show_up(x){
  3. if(x > 5){
  4. document.getElementById('extras').className = 'show';
  5. }else{
  6. document.getElementById('extras').className = 'hide';
  7. }
  8. }
  9. </script>
  10. <style>
  11. .hide{
  12. display:none;
  13. }
  14. </style>

If you fill file widgets in range 5-9 and then hide the last 5, they will still try to upload the files - so you could write something a bit "cleverer" to deal with this. This is just an example - I wouldn't use this in a production site.
PHP Syntax (Toggle Plain Text)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <script>
  5. function show_up(x){
  6.  
  7. if(x > 5){
  8. document.getElementById('extra').style.display = 'table-cell';
  9. document.getElementById('extras').style.display = 'none';
  10. }else{
  11. document.getElementById('extras').style.display = 'table-cell';
  12. document.getElementById('extra').style.display = 'none';
  13. }
  14. }
  15. </script>
  16. <style>
  17. .hide{
  18. display:none;
  19. }
  20. </style>
  21. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  22. <title>Untitled Document</title>
  23. </head>
  24.  
  25. <body>
  26. <form name="form" method="post">
  27. <input name="showups" type="radio" value="0" onclick="show_up(5);return false;"/><label for="show5">Show 5 upload fields</label>
  28. <input name="showups" id="show10" type="radio" value="1" onclick="show_up(10);return false;"/><label for="show10">Show 10 upload fields</label>
  29. <div id = "extra" class="show" style="display:none">
  30. <input type="file" name="upload[]" />
  31. <input type="file" name="upload[]" />
  32. <input type="file" name="upload[]" />
  33. <input type="file" name="upload[]" />
  34. <input type="file" name="upload[]" />
  35. <input type="file" name="upload[]" />
  36. <input type="file" name="upload[]" />
  37. <input type="file" name="upload[]" />
  38. <input type="file" name="upload[]" />
  39. <input type="file" name="upload[]" />
  40. </div>
  41. <div id = "extras" class="show" style="display:none">
  42. <input type="file" name="upload[]" />
  43. <input type="file" name="upload[]" />
  44. <input type="file" name="upload[]" />
  45. <input type="file" name="upload[]" />
  46. <input type="file" name="upload[]" />
  47. </div>
  48.  
  49. </form>
  50. </body>
  51. </html>
Quote ...
see once its working. but radio button checking problem. what is the solution for this.
Reputation Points: 21
Solved Threads: 35
Posting Pro
muralikalpana is offline Offline
534 posts
since Sep 2009
Nov 7th, 2009
-1
Re: radio button validation
Change this line to hide the extras by default:
PHP Syntax (Toggle Plain Text)
  1. <div id = "extras" class="hide">
Also you need a selected="selected" attribute inside the first radiobutton to ensure that the first one (5 file) is 'on'.
Sponsor
Featured Poster
Reputation Points: 1054
Solved Threads: 949
Sarcastic Poster
ardav is offline Offline
6,700 posts
since Oct 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: My OOP based login -- Help me start
Next Thread in PHP Forum Timeline: Plugin could not be activated because it triggered a fatal error.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC