Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##
- ## ------ [ ADD_PROFILE.asp ] ------
- ##
- <form method="POST" action="SUBMIT_PROFILE.asp">
- Name: <input type="text" name="tbName"/>
- Age: <input type="text" name="tbAge"/>
- Favorite Fruits:
- Apples: <input type="checkbox" name="cbFavFruit" value="Apples" /><br />
- Pears: <input type="checkbox" name="cbFavFruit" value="Pears" /><br />
- Bananas: <input type="checkbox" name="cbFavFruit" value="Bananas" /><br />
- <input type="submit" />
- </form>
- ##
- ## ------ [ SUBMIT_PROFILE.asp ] ------
- ##
- <%
- _tbName = Request.Form("tbName")
- _tbAge = Request.Form("tbAge")
- _cbFavFruit = Request.Form("cbFavFruit")
- Response.Write("Name: " & _tbName & "<br />")
- Response.Write("Age: " & _tbAge & "<br />")
- Response.Write("Favorite Fruits: " & _cbFavFruit & "<br />")
- ''I would insert these into the database
- ''eg. INSERT INTO tbl_UserProfiles VALUES (name, age, fav_fruits) VALUES (_tbName, _tbAge, _cbFavFruit)
- %>
- ##
- ## ------ [ SUBMIT_PROFILE.ASP SAMPLE OUTPUT ] ------
- ##
- Name: Neil
- Age: 31
- Favorite Fruits: Apples,Pears,Bannas
- ##
- ## 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...
- ## ------ [ EDIT_PROFILE.asp ] ------
- ##
- 'connect to database here
- 'then query the table and get recordset results, eg: objRS("fieldvalue")
- '
- <form method="POST" action="SUBMIT_EDITPROFILE.asp">
- Name: <input type="text" name="tbName" value="<%= objRS("name") %>" />
- Age: <input type="text" name="tbAge" value="<%= objRS("age") %>"/>
- Favorite Fruits:
- Apples: <input type="checkbox" name="cbFavFruit" value="Apples" <% if (InStr(objRS("favfruit"), "Apples")) > 0 then Response.Write(" checked") %>/><br />
- Pears: <input type="checkbox" name="cbFavFruit" value="Pears" <% if (InStr(objRS("favfruit"), "Pears")) > 0 then Response.Write(" checked") %>/><br />
- Bananas: <input type="checkbox" name="cbFavFruit" value="Bananas" <% if (InStr(objRS("favfruit"), "Bananas")) > 0 then Response.Write(" checked") %>/><br />
- <input type="submit" />
- </form>
- ## the hacky code is this:
- <% if (InStr(objRS("favfruit"), "Apples")) > 0 then Response.Write(" checked") %>
- 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!
- 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