Codeman0013 Posted June 22, 2006 Share Posted June 22, 2006 (edited) i have 2 select menu's side by side and i want when you click the button to move one from the left to the right or vice versa to check the database and update the table in teh database called doctor_matrix and it shoudl change the fields DOC_ID and DEPTCONTACT_ID either delete a field if its been deleted or add one if something was added my call right now is in vbscript its all messed up from the person that made this originally and its not working yet here is te code for the button and the code it calls.. <%' *** Edit Operations: declare variablesDim MM_editActionDim MM_abortEditDim MM_editQueryDim MM_editCmdDim MM_editConnectionDim MM_editTableDim MM_editRedirectUrlDim MM_editColumnDim MM_recordIdDim MM_fieldsStrDim MM_columnsStrDim MM_fieldsDim MM_columnsDim MM_typeArrayDim MM_formValDim MM_delimDim MM_altValDim MM_emptyValDim MM_iMM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))If (Request.QueryString <> "") ThenMM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)End If' boolean to abort record editMM_abortEdit = false' query string to executeMM_editQuery = ""%><%' *** Update Record: set variablesIf (CStr(Request("MM_update")) = "form1" And CStr(Request("MM_recordId")) <> "") ThenMM_editConnection = MM_connChristie_STRINGMM_editTable = "doctor_matrix"MM_editColumn = "DEPTCONTACT_ID"MM_recordId = "" + Request.Form("MM_recordId") + ""MM_editRedirectUrl = ""MM_fieldsStr = "CURRENTDEPT_ID|value"MM_columnsStr = "DEPTCONTACT_ID|none,none,NULL"' create the MM_fields and MM_columns arraysMM_fields = Split(MM_fieldsStr, "|")MM_columns = Split(MM_columnsStr, "|")' set the form valuesFor MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))Next' append the query string to the redirect URLIf (MM_editRedirectUrl <> "" And Request.QueryString <> "") ThenIf (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") ThenMM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryStringElseMM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryStringEnd IfEnd IfEnd If%><%' *** Update Record: construct a sql update statement and execute itIf (CStr(Request("MM_update")) <> "" And CStr(Request("MM_recordId")) <> "") Then' create the sql update statementMM_editQuery = "update " & MM_editTable & " set "For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2MM_formVal = MM_fields(MM_i+1)MM_typeArray = Split(MM_columns(MM_i+1),",")MM_delim = MM_typeArray(0)If (MM_delim = "none") Then MM_delim = ""MM_altVal = MM_typeArray(1)If (MM_altVal = "none") Then MM_altVal = ""MM_emptyVal = MM_typeArray(2)If (MM_emptyVal = "none") Then MM_emptyVal = ""If (MM_formVal = "") ThenMM_formVal = MM_emptyValElseIf (MM_altVal <> "") ThenMM_formVal = MM_altValElseIf (MM_delim = "'") Then ' escape quotesMM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"ElseMM_formVal = MM_delim + MM_formVal + MM_delimEnd IfEnd IfIf (MM_i <> LBound(MM_fields)) ThenMM_editQuery = MM_editQuery & ","End IfMM_editQuery = MM_editQuery & MM_columns(MM_i) & " = " & MM_formValNextMM_editQuery = MM_editQuery & " where " & MM_editColumn & " = " & MM_recordIdIf (Not MM_abortEdit) Then' execute the updateSet MM_editCmd = Server.CreateObject("ADODB.Command")MM_editCmd.ActiveConnection = MM_editConnectionMM_editCmd.CommandText = MM_editQueryMM_editCmd.ExecuteMM_editCmd.ActiveConnection.CloseIf (MM_editRedirectUrl <> "") ThenResponse.Redirect(MM_editRedirectUrl)End IfEnd IfEnd If%> Edited June 22, 2006 by aspnetguy Link to comment Share on other sites More sharing options...
justsomeguy Posted June 22, 2006 Share Posted June 22, 2006 For the first two examples, I recommend you dump VBScript and use Javascript to do the same thing. VBScript will only work in IE. And it's ugly. And it smells bad. And it eats all your food in the fridge, even if you have it labeled with your name on it. And it never buys the beer.For the last one, I'm not really wanting to debug Macromedia code. If anyone else wants to give that a shot, go ahead, but if all you're doing is taking the contents of two select boxes, and making sure that all of the items in one box are stored somewhere in the database, that's something like 30 or 40 lines of code anyway, it's not too much of a big deal. What exactly are you trying to do? Link to comment Share on other sites More sharing options...
Codeman0013 Posted June 22, 2006 Author Share Posted June 22, 2006 For the first two examples, I recommend you dump VBScript and use Javascript to do the same thing. VBScript will only work in IE. And it's ugly. And it smells bad. And it eats all your food in the fridge, even if you have it labeled with your name on it. And it never buys the beer.For the last one, I'm not really wanting to debug Macromedia code. If anyone else wants to give that a shot, go ahead, but if all you're doing is taking the contents of two select boxes, and making sure that all of the items in one box are stored somewhere in the database, that's something like 30 or 40 lines of code anyway, it's not too much of a big deal. What exactly are you trying to do?<{POST_SNAPBACK}> what i have is on the left in that box its the current departments and locations that the doctor is located in and it displayes out of the doctor matrix table the right side is all of the possible departments and locations displyed from the departments contact table and what i am wanting to do is when they click either button in between the two to move from one side to another have it post back and check the database and if its been added or deleted from the left table take the appropiate action in the database... Link to comment Share on other sites More sharing options...
justsomeguy Posted June 22, 2006 Share Posted June 22, 2006 OK, I guess there are a few ways you can do this.The first way is you have 2 boxes side by side, with maybe 2 buttons between them, with an arrow pointing to/from each box. You can highlight one or more items in a box, click the appropriate button, and the items move to the other box. As soon as you click the button, the database also gets updated, and the screen doesn't reload. This is the closest to how these work on Windows, but this will require a lot of client-side code, including AJAX, in addition to a lot of server-side code to handle the database stuff. AJAX might not also work properly on some browsers.The second way is to have something similar to the above, but instead of updating the database on each button click, it will have an additional submit button. When you finish moving everything around, you hit submit, the page gets reloaded, and the database gets updated. This is a whole lot easier and more reliable than the above.The third way is to not even use javascript on the client, where people won't be able to actually move the items themselves. What they see there is the two boxes, and only a submit button. They highlight in each box the items that they want to move to the other box, and then hit submit. The page reloads, and they see that the things they had selected are now in the other boxes. This is even easier than the above, but it might be slightly more confusing to the user if they don't have the buttons to move things from one box to another.When I've done things like this, I've usually gone with the third one. Once people learn how to use it, it's easy, and it doesn't require any client-side code at all. Link to comment Share on other sites More sharing options...
Codeman0013 Posted June 22, 2006 Author Share Posted June 22, 2006 OK, I guess there are a few ways you can do this.The first way is you have 2 boxes side by side, with maybe 2 buttons between them, with an arrow pointing to/from each box. You can highlight one or more items in a box, click the appropriate button, and the items move to the other box. As soon as you click the button, the database also gets updated, and the screen doesn't reload. This is the closest to how these work on Windows, but this will require a lot of client-side code, including AJAX, in addition to a lot of server-side code to handle the database stuff. AJAX might not also work properly on some browsers.The second way is to have something similar to the above, but instead of updating the database on each button click, it will have an additional submit button. When you finish moving everything around, you hit submit, the page gets reloaded, and the database gets updated. This is a whole lot easier and more reliable than the above.The third way is to not even use javascript on the client, where people won't be able to actually move the items themselves. What they see there is the two boxes, and only a submit button. They highlight in each box the items that they want to move to the other box, and then hit submit. The page reloads, and they see that the things they had selected are now in the other boxes. This is even easier than the above, but it might be slightly more confusing to the user if they don't have the buttons to move things from one box to another.When I've done things like this, I've usually gone with the third one. Once people learn how to use it, it's easy, and it doesn't require any client-side code at all.<{POST_SNAPBACK}> it doenst really matter how its done this is a total redesign the reason for the boxes is because its updating 2 differnt tables dreamweaver didnt like it becuase when you click submit it only did the one thing and did not want to open another connection unless you know how to do this i would like to see an example of the 3rd one and maybe i can do it.... or if possible make the 2nd one work where it will do 2 at once becuase this is an iframe inside of another page if that makes any sence to you... Link to comment Share on other sites More sharing options...
justsomeguy Posted June 22, 2006 Share Posted June 22, 2006 Here are some examples with java script:http://www.mattkruse.com/javascript/selectbox/On the server side, the script would find out what is in each box, and depending on how the database is set up, it would probably just delete everything out of a table for that doctor and then re-add everything that was in the box. Link to comment Share on other sites More sharing options...
Codeman0013 Posted June 23, 2006 Author Share Posted June 23, 2006 Here are some examples with java script:http://www.mattkruse.com/javascript/selectbox/On the server side, the script would find out what is in each box, and depending on how the database is set up, it would probably just delete everything out of a table for that doctor and then re-add everything that was in the box.<{POST_SNAPBACK}> now if there was only a page like this one that had the ability to do the server side stuff to i would be set but i dont see that anywhere on this page dang... Link to comment Share on other sites More sharing options...
aspnetguy Posted June 23, 2006 Share Posted June 23, 2006 why do you want ot do this server side? Incase JS is disabled? You would have to refresht he page for every button click, it would be much slower than using JS. Link to comment Share on other sites More sharing options...
Codeman0013 Posted June 23, 2006 Author Share Posted June 23, 2006 why do you want ot do this server side? Incase JS is disabled? You would have to refresht he page for every button click, it would be much slower than using JS.<{POST_SNAPBACK}> i can do this client side where it checks and updates the database???? please show me how if its possible here are the fields in the table doctor_matrix i'm trying to update DOC_ID and DEPTCONTACT_ID those either need to be deleted and readded if its changed or added if they are adding a new one please help me if its possible Link to comment Share on other sites More sharing options...
aspnetguy Posted June 23, 2006 Share Posted June 23, 2006 sorry thats what i get for not reading hte entire thread.I didn't realise you wanted to check/update the database everytime an itme from select1 gets sent to select2.You could just have an update button underneath so you send all the items you want over to select2 then hit update button and submit the form to a php page to process and update database. Link to comment Share on other sites More sharing options...
aspnetguy Posted June 23, 2006 Share Posted June 23, 2006 if you have your heart set on checking for each item change then look into AJAX, it lets javascript execute server side functions without refreshing the page. Link to comment Share on other sites More sharing options...
Codeman0013 Posted June 23, 2006 Author Share Posted June 23, 2006 if you have your heart set on checking for each item change then look into AJAX, it lets javascript execute server side functions without refreshing the page.<{POST_SNAPBACK}> i have heard of AJAX but i am not familular with it is it hard??? also this is an IFRAME inside of another page would it be possible to put that inside there just for that to where it does not refresh the rest of the page just hte iframe?? Link to comment Share on other sites More sharing options...
aspnetguy Posted June 23, 2006 Share Posted June 23, 2006 AJAX is not hard it just might take you a while to get used to it. I find deciding what to return from the server side function and then how to parse it takes the most effort.I suppose if you want it in an iframe it wouldn't matter that much if it refreshed. I like to avoid frames as much as possible. Link to comment Share on other sites More sharing options...
Codeman0013 Posted June 23, 2006 Author Share Posted June 23, 2006 AJAX is not hard it just might take you a while to get used to it. I find deciding what to return from the server side function and then how to parse it takes the most effort.I suppose if you want it in an iframe it wouldn't matter that much if it refreshed. I like to avoid frames as much as possible.<{POST_SNAPBACK}> well i had this all in one page but i did not know how to rewrite the query that was already made by a previous person to include a 2nd table and make it work could i simply add an update button or is it possible to make the moving buttons do that? Link to comment Share on other sites More sharing options...
aspnetguy Posted June 23, 2006 Share Posted June 23, 2006 the only way to make hte moving buttons do that without refreshing the page is with AJAX Link to comment Share on other sites More sharing options...
Codeman0013 Posted June 23, 2006 Author Share Posted June 23, 2006 the only way to make hte moving buttons do that without refreshing the page is with AJAX<{POST_SNAPBACK}> do you think it would be easier to have them move it and a 2nd submit button on there? or is there somewhere i can have someone help me with ajax programming becuase i have been looking at it and i'm totally lost on it Link to comment Share on other sites More sharing options...
aspnetguy Posted June 23, 2006 Share Posted June 23, 2006 I think the easiest thing would be to move all the items you want to the second list then hit an update button and have php process them all at once.I am not very strong in ajax but I could try and help you out if you decide you want to go that route. Link to comment Share on other sites More sharing options...
Codeman0013 Posted June 23, 2006 Author Share Posted June 23, 2006 i'm thinking i'm going to have to do ajax i think a 2nd submit button on the page would confuse the user grr... sometimes the easier thing end up being the hardest Link to comment Share on other sites More sharing options...
aspnetguy Posted June 23, 2006 Share Posted June 23, 2006 i'm thinking i'm going to have to do ajax i think a 2nd submit button on the page would confuse the user grr... sometimes the easier thing end up being the hardest<{POST_SNAPBACK}> Well trying to make it easier for the user usually makes it hard for you to develop, that's a given Link to comment Share on other sites More sharing options...
Codeman0013 Posted June 23, 2006 Author Share Posted June 23, 2006 Well trying to make it easier for the user usually makes it hard for you to develop, that's a given <{POST_SNAPBACK}> would the javascript forum here be able to help me program this in ajax? Link to comment Share on other sites More sharing options...
aspnetguy Posted June 23, 2006 Share Posted June 23, 2006 well you may end up posting here and in the javascript forum to get the process done. AJAX uses javascript on the client side as you know and then ASP or PHP, ect on the server side and they talk together.I suggest you take a look at the AJAX tutorial at www.w3schools.com and get familiar witht he basics first. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now