Advertisement
Guest User

Untitled

a guest
Sep 15th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASP 2.62 KB | None | 0 0
  1. ##
  2. ## ------ [ ADD_PROFILE.asp ] ------
  3. ##
  4.  
  5. <form method="POST" action="SUBMIT_PROFILE.asp">
  6.   Name:    <input type="text" name="tbName"/>
  7.   Age:     <input type="text" name="tbAge"/>
  8.   Favorite Fruits:
  9.   Apples:  <input type="checkbox" name="cbFavFruit" value="Apples" /><br />
  10.   Pears:   <input type="checkbox" name="cbFavFruit" value="Pears" /><br />
  11.   Bananas: <input type="checkbox" name="cbFavFruit" value="Bananas" /><br />
  12.   <input type="submit" />
  13. </form>
  14.  
  15.  
  16. ##
  17. ## ------ [ SUBMIT_PROFILE.asp ] ------
  18. ##
  19.  
  20. <%
  21. _tbName = Request.Form("tbName")
  22. _tbAge = Request.Form("tbAge")
  23. _cbFavFruit = Request.Form("cbFavFruit")
  24.  
  25. Response.Write("Name: " & _tbName & "<br />")
  26. Response.Write("Age: " & _tbAge & "<br />")
  27. Response.Write("Favorite Fruits: " & _cbFavFruit & "<br />")
  28.  
  29. ''I would insert these into the database
  30. ''eg. INSERT INTO tbl_UserProfiles VALUES (name, age, fav_fruits) VALUES (_tbName, _tbAge, _cbFavFruit)
  31. %>
  32.  
  33.  
  34. ##
  35. ## ------ [ SUBMIT_PROFILE.ASP SAMPLE OUTPUT ] ------
  36. ##
  37.  
  38. Name: Neil
  39. Age: 31
  40. Favorite Fruits: Apples,Pears,Bannas
  41.  
  42.  
  43.  
  44. ##
  45. ## If I then needed to repopulate a form on a page (lets call it EDIT_PROFILE.asp) I would use some "hacky" method to perform this eg...
  46. ## ------ [ EDIT_PROFILE.asp ] ------
  47. ##
  48.  
  49. 'connect to database here
  50. 'then query the table and get recordset results, eg: objRS("fieldvalue")
  51. '
  52.  
  53. <form method="POST" action="SUBMIT_EDITPROFILE.asp">
  54.   Name:    <input type="text" name="tbName" value="<%= objRS("name") %>" />
  55.   Age:     <input type="text" name="tbAge" value="<%= objRS("age") %>"/>
  56.   Favorite Fruits:
  57.   Apples:  <input type="checkbox" name="cbFavFruit" value="Apples" <% if (InStr(objRS("favfruit"), "Apples")) > 0 then Response.Write(" checked") %>/><br />
  58.   Pears:   <input type="checkbox" name="cbFavFruit" value="Pears" <% if (InStr(objRS("favfruit"), "Pears")) > 0 then Response.Write(" checked") %>/><br />
  59.   Bananas: <input type="checkbox" name="cbFavFruit" value="Bananas" <% if (InStr(objRS("favfruit"), "Bananas")) > 0 then Response.Write(" checked") %>/><br />
  60.   <input type="submit" />
  61. </form>
  62.  
  63.  
  64. ## the hacky code is this:
  65. <% if (InStr(objRS("favfruit"), "Apples")) > 0 then Response.Write(" checked") %>
  66.  
  67. to break that down, I check if "Apples" is in the string/variable/recordset objRS("favfruit"). If it is it will return a number greater than 0, otherwise it will return a negative number, or 0. So if a number greater than 0 is returned, I output the word "checked" into the HTML checkbox field, which inturn will mark the checkbox with a tick!
  68. This is the way I have always done it, but im not keen on this method, surley there must be a neater way?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement