Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

I want to save the values of checkbox when the user clicks the save button.

Posted on 2004-11-21
119
Medium Priority
?
262 Views
Last Modified: 2012-05-05
i have been trying to add  2checkbox into this form beside each text area,
and to be saved with the value of the text area too when the
user clicks the save button .
This form haves several text areas and beside each  text area there is a save button which when clicked the value in that field ONLY is saved in the db .
This form also have a submit button that when clicked all the text fields is saved in the db like any other form.
check this link to see what i mean:
http://ccc.1asphost.com/kotty1234/cert/formtest.asp
I want to save the values of the check box too with the value of the textarea when the user clicks the save button?
Here is the code of the form:
<!-- -->
<script language="javascript">
function fSaveSingle(strDBField,strFormValue,iIsString){
     iSubmit = 1;
     if (iSubmit == 1){
          if (document.forms.frmRealForm[strFormValue].value == ""){
               alert("This field cannot be empty.");
               iSubmit = 0;
          }
     }
     if (iSubmit == 1){
          document.forms.frmSaveSingle.strDBField.value = strDBField;
          document.forms.frmSaveSingle.strFormValue.value = document.forms.frmRealForm[strFormValue].value;
          document.forms.frmSaveSingle.iIsString.value = iIsString;
          document.forms.frmSaveSingle.submit();
     }
}
</script>
<%
'BELOW ARE A SERIES OF FUNCTIONS I'VE WRITTEN FOR SIMPLIFYING INSERT STATEMENT BUILDING
dim strBuildFields,strBuildValues
function fInitQuery()
     strBuildFields = ""
     strBuildValues = ""
end function

function fAddValue(strField,strValue,iString)
     if len(strBuildFields) = 0 then
          strDelimiter = ""
     else
          strDelimiter = ","
     end if
     strBuildFields = strBuildFields & strDelimiter & strField
     'iString should be 1 if it is a string, 0 if it is an integer
     if iString = 1 then
          strQuote = "'"
     else
          strQuote = ""
     end if
     strBuildValues = strBuildValues & strDelimiter & strQuote & strValue & strQuote
end function

function fFinalQuery(strTable)
     strBuildSQL = "INSERT INTO " & strTable & " (" & strBuildFields & ")" & " VALUES (" & strBuildValues & ")"
     fFinalQuery = strBuildSQL
end function
'ABOVE ARE A SERIES OF FUNCITON I'VE WRITTEN FOR SIMPLIFYING INSERT STATEMENT BUILDING
 
     Dim straccessdb, conn, strcon
     strAccessDB = "db1.mdb"
     Set Conn = Server.CreateObject("ADODB.Connection")
     strCon = "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=; DBQ=" & Server.MapPath(strAccessDB)
     conn.Open strCon
     Set rs = Server.createobject("ADODB.recordset")
     dim M_USERNAME
     M_USERNAME = session("user")
       
if request.form("iSaveSingle") = 1 then
     strFieldName = request.form("strDBField")
     strFieldValue = request.form("strFormValue")
     iIsString = request.form("iIsString")
     strQuote = ""
     if iIsString = 1 then
          strQuote = "'"
     end if
     strSQL = "UPDATE check "
     strSQL = strSQL & "SET " & strFieldName & " = " & strQuote & strFieldValue & strQuote & " "
     strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
     conn.execute(strSQL)
     'response.write("<!-- [JAVASCRIPT POPUP WINDOW CODE HERE FOR PDF FILE] -->");
end if
if request.form("iSaveAll") = "1" then
    strSQL = "UPDATE check SET "
     strSQL = strSQL & "dbTextFieldName = '" & request.form("txtTextField") & "'"
     strSQL = strSQL & ",dbTextFieldName2 = '" & request.form("txtTextField2") & "'"
     strSQL = strSQL & " WHERE M_USERNAME = '" & session("user") & "'"
     conn.execute(strSQL)
end if
%>
<%= strSQL %>
<!-- Hidden Form Here -->
<form method="POST" name="frmSaveSingle">
     <input type="hidden" name="iSaveSingle" value="1">
     <input type="hidden" name="strDBField" value="">
     <input type="hidden" name="strFormValue" value="">
     <input type="hidden" name="iIsString" value="0">    
</form>

<!-- Real Form Here  [REPLACE BELOW WITH YOUR EXISTING FORM, JUST APPLY THE BUTTON ONCLICK SYNTAX TO THE SAVE BUTTONS]-->
<form name="frmRealForm" method="POST">
     <input type="hidden" name="iSaveAll" value="1">
     <textarea name="txtTextField" value=""></textarea>
  <input type="checkbox" name="checkbox" value="checkbox">
  <input type="checkbox" name="checkbox2" value="checkbox">
  <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName','txtTextField',1)">
       <br>
  <textarea  name="txtTextField2" value=""></textarea>
  <input type="checkbox" name="checkbox3" value="checkbox">
  <input type="checkbox" name="checkbox4" value="checkbox">
  <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName2','txtTextField2',1);window.location = 'form1.asp?M_USERNAME=<% response.write (session("user"))%>';">

  <br> <input type="submit" value="SAVE ALL">
</form>
<!-- -->
0
Comment
Question by:Melfeky
  • 63
  • 44
  • 10
  • +2
119 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 12640131
After you submit() the form are also the checkbox values submitted when the checkbox is checked.
So it is not clear what your question is?
Do you want to add the checkbox value "checkbox" to some other field values?
0
 

Author Comment

by:Melfeky
ID: 12640147
1-If u viewed the link u will see there re 2 text areas and beside eachone of them there is a save button.
When the user enters values in the text area and click the save button ,the value in that field is saved in the db.
What i want to do is to make those 2 checkboxes beside the text area also be saved plus the value that is entered in the text area into the db.
2-the save all  button is used to save all the data in the form all at one time into an access db

i hope my idea is clear now.
thanks
0
 

Author Comment

by:Melfeky
ID: 12640160
the part of the text re works fine, but i cann't do the same with the checkbox
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 10

Expert Comment

by:slamhound
ID: 12641465
I would call each check box something similar to each submit button. So checkbox1a and checbox1b would be associated with submit1, checkbox2a and checkbox2b would be associated with submit2 and so on. You know what submit button is pressed so you then check the two checkboxes associated with this button. If they turn up as values, set them to true. If they turn up as null, set them as false.

I *think* this is what you are asking about?
0
 
LVL 13

Assisted Solution

by:nurbek
nurbek earned 400 total points
ID: 12642317
Melfeky,
in your asp code
there is only text from the textarea in inserted to database
to add checkboxes also

if request.form("iSaveSingle") = 1 then
     strFieldName = request.form("strDBField")
     strFieldValue = request.form("strFormValue")
     iIsString = request.form("iIsString")
     strQuote = ""
     if iIsString = 1 then
          strQuote = "'"
     end if
     strSQL = "UPDATE check "
     strSQL = strSQL & "SET " & strFieldName & " = " & strQuote & strFieldValue & strQuote & " "
'add check boxes
     strSQL = strSQL & ", checkboxfield = '" & Request.Form("checkbox") & "' "
     strSQL = strSQL & ", checkboxfield2 = '" & Request.Form("checkbox2") & "' "
     strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
     conn.execute(strSQL)
     'response.write("<!-- [JAVASCRIPT POPUP WINDOW CODE HERE FOR PDF FILE] -->");
end if
if request.form("iSaveAll") = "1" then
    strSQL = "UPDATE check SET "
     strSQL = strSQL & "dbTextFieldName = '" & request.form("txtTextField") & "'"
     strSQL = strSQL & ",dbTextFieldName2 = '" & request.form("txtTextField2") & "'"
'add check boxes
     strSQL = strSQL & ", checkboxfield = '" & Request.Form("checkbox") & "' "
     strSQL = strSQL & ", checkboxfield2 = '" & Request.Form("checkbox2") & "' "
     strSQL = strSQL & " WHERE M_USERNAME = '" & session("user") & "'"
     conn.execute(strSQL)
end if
0
 

Author Comment

by:Melfeky
ID: 12643874
nurbek :
i have tried your code but i got this error, though i have already set the new checkboxs the same name into the db with data type:yes/no and format :true/false

Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E07)
[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
/pdf1/formtest.asp, line 84

from what i can see in ur suggestion is that u are dealing with the text are the same like checkbox:
here is all the code of the form would someone look at it and let me know what is wrong?
<!-- -->
<script language="javascript">
function fSaveSingle(strDBField,strFormValue,iIsString){
     iSubmit = 1;
     if (iSubmit == 1){
          if (document.forms.frmRealForm[strFormValue].value == ""){
               alert("This field cannot be empty.");
               iSubmit = 0;
          }
     }
     if (iSubmit == 1){
          document.forms.frmSaveSingle.strDBField.value = strDBField;
          document.forms.frmSaveSingle.strFormValue.value = document.forms.frmRealForm[strFormValue].value;
          document.forms.frmSaveSingle.iIsString.value = iIsString;
          document.forms.frmSaveSingle.submit();
     }
}
</script>
<%
'BELOW ARE A SERIES OF FUNCTIONS I'VE WRITTEN FOR SIMPLIFYING INSERT STATEMENT BUILDING
dim strBuildFields,strBuildValues
function fInitQuery()
     strBuildFields = ""
     strBuildValues = ""
end function

function fAddValue(strField,strValue,iString)
     if len(strBuildFields) = 0 then
          strDelimiter = ""
     else
          strDelimiter = ","
     end if
     strBuildFields = strBuildFields & strDelimiter & strField
     'iString should be 1 if it is a string, 0 if it is an integer
     if iString = 1 then
          strQuote = "'"
     else
          strQuote = ""
     end if
     strBuildValues = strBuildValues & strDelimiter & strQuote & strValue & strQuote
end function

function fFinalQuery(strTable)
     strBuildSQL = "INSERT INTO " & strTable & " (" & strBuildFields & ")" & " VALUES (" & strBuildValues & ")"
     fFinalQuery = strBuildSQL
end function
'ABOVE ARE A SERIES OF FUNCITON I'VE WRITTEN FOR SIMPLIFYING INSERT STATEMENT BUILDING
 
     Dim straccessdb, conn, strcon
     strAccessDB = "db1.mdb"
     Set Conn = Server.CreateObject("ADODB.Connection")
     strCon = "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=; DBQ=" & Server.MapPath(strAccessDB)
     conn.Open strCon
     Set rs = Server.createobject("ADODB.recordset")
     dim M_USERNAME
     M_USERNAME = session("user")
       
if request.form("iSaveSingle") = 1 then
     strFieldName = request.form("strDBField")
     strFieldValue = request.form("strFormValue")
     iIsString = request.form("iIsString")
     if len(request.form("checkbox")) >0 then
                    checkbox = True
             else
                       checkbox = False
              end if
      if len(request.form("checkbox2")) >0 then
                    checkbox2 = True
             else
                       checkbox2 = False
              end if
       strQuote = ""
     if iIsString = 1 then
          strQuote = "'"
     end if
     strSQL = "UPDATE check "
     strSQL = strSQL & "SET " & strFieldName & " = " & strQuote & strFieldValue & strQuote & " "
'add check boxes
 strSQL = strSQL & ", checkboxfield = '" & Request.Form("checkbox") & "' "
     strSQL = strSQL & ", checkboxfield2 = '" & Request.Form("checkbox2") & "' "
  strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
     '  response.write strsql
'response.end
       conn.execute(strSQL)
     'response.write("<!-- [JAVASCRIPT POPUP WINDOW CODE HERE FOR PDF FILE] -->");
end if
if request.form("iSaveAll") = "1" then
    strSQL = "UPDATE check SET "
     strSQL = strSQL & "dbTextFieldName = '" & request.form("txtTextField") & "'"
     strSQL = strSQL & "dbTextFieldName2 = '" & request.form("txtTextField2") & "'"
'add check boxes
    strSQL = strSQL & ", checkboxfield = '" & Request.Form("checkbox") & "' "
     strSQL = strSQL & ", checkboxfield2 = '" & Request.Form("checkbox2") & "' "
     strSQL = strSQL & " WHERE M_USERNAME = '" & session("user") & "'"
   ' response.write strsql
'response.end
       conn.execute(strSQL)
end if
%>
<%= strSQL %>
<!-- Hidden Form Here -->
<form method="POST" name="frmSaveSingle">
     <input type="hidden" name="iSaveSingle" value="1">
     <input type="hidden" name="strDBField" value="">
     <input type="hidden" name="strFormValue" value="">
     <input type="hidden" name="iIsString" value="0">    
</form>

<!-- Real Form Here  [REPLACE BELOW WITH YOUR EXISTING FORM, JUST APPLY THE BUTTON ONCLICK SYNTAX TO THE SAVE BUTTONS]-->
<form name="frmRealForm" method="POST">
     <input type="hidden" name="iSaveAll" value="1">
     <textarea name="txtTextField" value=""></textarea>
  <input type="checkbox" name="checkbox" value="">
  <input type="checkbox2" name="checkbox2" value="">
   
  <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName','txtTextField',1)">
       <br>
  <textarea  name="txtTextField2" value=""></textarea>
  <input type="checkbox" name="checkbox3" value="">
  <input type="checkbox" name="checkbox4" value="">
  <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName2','txtTextField2',1);window.location = 'form1.asp?M_USERNAME=<% response.write (session("user"))%>';">

  <br> <input type="submit" value="SAVE ALL">
</form>
<!-- -->


0
 

Author Comment

by:Melfeky
ID: 12643883
slamhound , i think your idea is correct but would u tell me how to do this in my example?
Thanks guys
0
 
LVL 13

Expert Comment

by:nurbek
ID: 12643920
checkboxfield  and checkboxfield2 fields in the database

'add check boxes
    strSQL = strSQL & ", checkboxfield = " & checkbox & " "
     strSQL = strSQL & ", checkboxfield2 = " & checkbox2 & " "
0
 

Author Comment

by:Melfeky
ID: 12644015
I have changed those two lines in the INSERT and UPDATE statment.Is this right?
But the value of the checkbox is always false.
I always get this :

UPDATE check SET dbTextFieldName = 'c' , checkboxfield = False , checkboxfield2 = False WHERE M_USERNAME = 'dodo'
0
 

Author Comment

by:Melfeky
ID: 12644070
nd by the way the form was always giving me error untill i added this

 if len(request.form("checkbox")) >0 then
                    checkbox = True
             else
                       checkbox = False
              end if
      if len(request.form("checkbox2")) >0 then
                    checkbox2 = True
             else
                       checkbox2 = False
              end if

but i don't know why it is always giving me the false value?
should we save its value too in the button beside it with the value of the text area? and if so how would we do that?
0
 
LVL 13

Expert Comment

by:nurbek
ID: 12644105
It seems to be ok
(below code works on savesingle, because this is inside the savesingle IF .. End If  )
 
    if len(request.form("checkbox")) >0 then
                    checkbox = True
             else
                       checkbox = False
              end if
     if len(request.form("checkbox2")) >0 then
                    checkbox2 = True
             else
                       checkbox2 = False
              end if

0
 

Author Comment

by:Melfeky
ID: 12644149
and why do i always get the false value from the checkboxes.
i hve added those lines :
  response.write strsql
response.end
so i always see their values false.

UPDATE check SET dbTextFieldName = 'c' , checkboxfield = False , checkboxfield2 = False WHERE M_USERNAME = 'dodo'
0
 
LVL 13

Expert Comment

by:nurbek
ID: 12644303
<input type="checkbox" name="checkbox" value="">

there is no value assigned

<input type="checkbox" name="checkbox" value="1">

then try
if checked it returns 1
then your code will return true
else
nothing




0
 

Author Comment

by:Melfeky
ID: 12644547
here is what i have done:
first i set the value to 1but got the same false value.
Then i did this:
<input type="checkbox" name="checkbox"
     <%
               if checkbox= true then
                    response.write(" checked ")
                     end if
               %>>
0
 
LVL 13

Expert Comment

by:nurbek
ID: 12644603
try this, and let me know what is written?

<%
    if len(request.form("checkbox")) >0 then
                    checkbox = True
             else
                       checkbox = False
              end if
     if len(request.form("checkbox2")) >0 then
                    checkbox2 = True
             else
                       checkbox2 = False
              end if

Response.write("checkbox1 = " & checkbox & "<br>checkbox2=" & checkbox2)
Response.End()
%>


<form ...>
<input type="checkbox" name="checkbox" value="1">
<input type="checkbox" name="checkbox2" value="1">
...
...
</form>
0
 

Author Comment

by:Melfeky
ID: 12644649
this is what is written:
checkbox1 = False
checkbox2=False
0
 
LVL 13

Expert Comment

by:nurbek
ID: 12644692
it works on mine :)

i think, you are missing something

could you post your all code?
0
 

Author Comment

by:Melfeky
ID: 12644828
<!--;window.location = 'form1.asp?M_USERNAME=<% response.write (session("user"))%>'; -->
<script language="javascript">
function fSaveSingle(strDBField,strFormValue,iIsString){
     iSubmit = 1;
     if (iSubmit == 1){
          if (document.forms.frmRealForm[strFormValue].value == ""){
               alert("This field cannot be empty.");
               iSubmit = 0;
          }
     }
     if (iSubmit == 1){
          document.forms.frmSaveSingle.strDBField.value = strDBField;
          document.forms.frmSaveSingle.strFormValue.value = document.forms.frmRealForm[strFormValue].value;
          document.forms.frmSaveSingle.iIsString.value = iIsString;
          document.forms.frmSaveSingle.submit();
     }
}
</script>
<%
'BELOW ARE A SERIES OF FUNCTIONS I'VE WRITTEN FOR SIMPLIFYING INSERT STATEMENT BUILDING
dim strBuildFields,strBuildValues
function fInitQuery()
     strBuildFields = ""
     strBuildValues = ""
end function

function fAddValue(strField,strValue,iString)
     if len(strBuildFields) = 0 then
          strDelimiter = ""
     else
          strDelimiter = ","
     end if
     strBuildFields = strBuildFields & strDelimiter & strField
     'iString should be 1 if it is a string, 0 if it is an integer
     if iString = 1 then
          strQuote = "'"
     else
          strQuote = ""
     end if
     strBuildValues = strBuildValues & strDelimiter & strQuote & strValue & strQuote
end function

function fFinalQuery(strTable)
     strBuildSQL = "INSERT INTO " & strTable & " (" & strBuildFields & ")" & " VALUES (" & strBuildValues & ")"
     fFinalQuery = strBuildSQL
end function
'ABOVE ARE A SERIES OF FUNCITON I'VE WRITTEN FOR SIMPLIFYING INSERT STATEMENT BUILDING
 
     Dim straccessdb, conn, strcon
     strAccessDB = "db1.mdb"
     Set Conn = Server.CreateObject("ADODB.Connection")
     strCon = "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=; DBQ=" & Server.MapPath(strAccessDB)
     conn.Open strCon
     Set rs = Server.createobject("ADODB.recordset")
     dim M_USERNAME
     M_USERNAME = session("user")
       
if request.form("iSaveSingle") = 1 then
     strFieldName = request.form("strDBField")
     strFieldValue = request.form("strFormValue")
     iIsString = request.form("iIsString")
      if len(request.form("checkbox")) >0 then
                    checkbox = True
             else
                       checkbox = False
              end if
     if len(request.form("checkbox2")) >0 then
                    checkbox2 = True
             else
                       checkbox2 = False
              end if

Response.write("checkbox1 = " & checkbox & "<br>checkbox2=" & checkbox2)
Response.End()

       strQuote = ""
     if iIsString = 1 then
          strQuote = "'"
     end if
     strSQL = "UPDATE check "
     strSQL = strSQL & "SET " & strFieldName & " = " & strQuote & strFieldValue & strQuote & " "
'add check boxes
  strSQL = strSQL & ", checkboxfield = " & checkbox & " "
     strSQL = strSQL & ", checkboxfield2 = " & checkbox2 & " "

' strSQL = strSQL & ", checkboxfield = '" & Request.Form("checkbox") & "' "
   '  strSQL = strSQL & ", checkboxfield2 = '" & Request.Form("checkbox2") & "' "
  strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
     '  response.write strsql
'response.end
       conn.execute(strSQL)
     'response.write("<!-- [JAVASCRIPT POPUP WINDOW CODE HERE FOR PDF FILE] -->");
end if
if request.form("iSaveAll") = "1" then
    strSQL = "UPDATE check SET "
     strSQL = strSQL & "dbTextFieldName = '" & request.form("txtTextField") & "'"
     strSQL = strSQL & "dbTextFieldName2 = '" & request.form("txtTextField2") & "'"
'add check boxes
  strSQL = strSQL & ", checkboxfield = " & checkbox & " "
     strSQL = strSQL & ", checkboxfield2 = " & checkbox2 & " "
     strSQL = strSQL & " WHERE M_USERNAME = '" & session("user") & "'"
  response.write strsql
response.end
       conn.execute(strSQL)
end if
%>
<%= strSQL %>
<!-- Hidden Form Here -->
<form method="POST" name="frmSaveSingle">
     <input type="hidden" name="iSaveSingle" value="1">
     <input type="hidden" name="strDBField" value="">
     <input type="hidden" name="strFormValue" value="">
     <input type="hidden" name="iIsString" value="0">    
</form>

<!-- Real Form Here  [REPLACE BELOW WITH YOUR EXISTING FORM, JUST APPLY THE BUTTON ONCLICK SYNTAX TO THE SAVE BUTTONS]-->
<form name="frmRealForm" method="POST">
     <input type="hidden" name="iSaveAll" value="1">
     <textarea name="txtTextField" value=""></textarea>
  <input type="checkbox" name="checkbox" value="1">
<input type="checkbox" name="checkbox2" value="1">

   
  <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName','txtTextField',1)">
       <br>
  <textarea  name="txtTextField2" value=""></textarea>
  <input type="checkbox" name="checkbox3" value="1">
  <input type="checkbox" name="checkbox4" value="1">
  <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName2','txtTextField2',1)">

  <br> <input type="submit" value="SAVE ALL">
</form>
<!-- -->
0
 

Author Comment

by:Melfeky
ID: 12644999
so what do u think is missing here?
0
 
LVL 13

Expert Comment

by:nurbek
ID: 12645023
i found, where is the problem is :)

when you click to save it submits the hidden form :)
theres is no checkboxes

add check boxes and some code into javascript


<form method="POST" name="frmSaveSingle">
     <input type="hidden" name="iSaveSingle" value="1">
     <input type="hidden" name="strDBField" value="">
     <input type="hidden" name="strFormValue" value="">
     <input type="hidden" name="iIsString" value="0">    
    <input type="hidden" name="checkbox" value="">
    <input type="hidden" name="checkbox2" value="">
</form>

in your javascipt add

     if (iSubmit == 1){
          document.forms.frmSaveSingle.strDBField.value = strDBField;
          document.forms.frmSaveSingle.strFormValue.value = document.forms.frmRealForm[strFormValue].value;
          document.forms.frmSaveSingle.iIsString.value = iIsString;
              //below code is added
              document.forms.frmSaveSingle.checkbox.value = document.forms.frmRealForm.checkbox.value;
              document.forms.frmSaveSingle.checkbox2.value = document.forms.frmRealForm.checkbox2.value;
          document.forms.frmSaveSingle.submit();
     }
0
 

Author Comment

by:Melfeky
ID: 12645355
you are the best.:)
0
 

Author Comment

by:Melfeky
ID: 12645369
but i have got one little thing,
i want when the user opens this form he can see the stored value that he save last time, can this be done?
0
 
LVL 13

Expert Comment

by:nurbek
ID: 12645520
you make it a bit complicated :)
actually one form would be enough

' read  the data from database

if request.form("iSaveSingle") <>"1" and request.form("iSaveAll") = "1" Then
strSQL ="SELECT * FROM check  WHERE M_USERNAME = '" & Session("user") & "'"
Set iRS = conn.Execute(strSQL)

   If not iRS.Eof Then
    'get the data
   txtTextField = iRS("txtTextField")
   txtTextField2 = iRS("txtTextField2")
    If  iRS("checkbox") Then checkbox="checked"
   If  iRS("checkbox2") Then checkbox2="checked"
   If  iRS("checkbox3") Then checkbox3="checked"
   If  iRS("checkbox4") Then checkbox4="checked"

  End If
Set iRS = Nothing

End If


<form name="frmRealForm" method="POST">
     <input type="hidden" name="iSaveAll" value="1">
     <textarea name="txtTextField" value="<%=txtTextField%>"></textarea>
  <input type="checkbox" name="checkbox" value="1" <%=Response.write(checkbox)%>>>
<input type="checkbox" name="checkbox2" value="1" <%=Response.write(checkbox2)%>>>

   
  <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName','txtTextField',1)">
       <br>
  <textarea  name="txtTextField2" value="<%=txtTextField2%>"></textarea>
  <input type="checkbox" name="checkbox3" value="1" <%=Response.write(checkbox3)%>>
  <input type="checkbox" name="checkbox4" value="1" <%=Response.write(checkbox4)%>>>
  <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName2','txtTextField2',1)">

  <br> <input type="submit" value="SAVE ALL">
</form>
0
 

Author Comment

by:Melfeky
ID: 12646267
There is something strange is happening:
1-No values are displayed into the fields when the user opens the form.
2-The checkboxs are always set to TRUE even if they where not checked.


Here is all the form after setting all the fields, would u check it:
<!--;window.location = 'form1.asp?M_USERNAME=<% response.write (session("user"))%>'; -->
<script language="javascript">
function fSaveSingle(strDBField,strFormValue,iIsString){
     iSubmit = 1;
     if (iSubmit == 1){
          if (document.forms.frmRealForm[strFormValue].value == ""){
               alert("This field cannot be empty.");
               iSubmit = 0;
          }
     }
      if (iSubmit == 1){
          document.forms.frmSaveSingle.strDBField.value = strDBField;
          document.forms.frmSaveSingle.strFormValue.value = document.forms.frmRealForm[strFormValue].value;
          document.forms.frmSaveSingle.iIsString.value = iIsString;
            //below code is added
            document.forms.frmSaveSingle.checkbox.value = document.forms.frmRealForm.checkbox.value;
            document.forms.frmSaveSingle.checkbox2.value = document.forms.frmRealForm.checkbox2.value;
                    document.forms.frmSaveSingle.checkbox3.value = document.forms.frmRealForm.checkbox3.value;
            document.forms.frmSaveSingle.checkbox4.value = document.forms.frmRealForm.checkbox4.value;

              document.forms.frmSaveSingle.submit();
     }
}
</script>
<%
'BELOW ARE A SERIES OF FUNCTIONS I'VE WRITTEN FOR SIMPLIFYING INSERT STATEMENT BUILDING
dim strBuildFields,strBuildValues
function fInitQuery()
     strBuildFields = ""
     strBuildValues = ""
end function

function fAddValue(strField,strValue,iString)
     if len(strBuildFields) = 0 then
          strDelimiter = ""
     else
          strDelimiter = ","
     end if
     strBuildFields = strBuildFields & strDelimiter & strField
     'iString should be 1 if it is a string, 0 if it is an integer
     if iString = 1 then
          strQuote = "'"
     else
          strQuote = ""
     end if
     strBuildValues = strBuildValues & strDelimiter & strQuote & strValue & strQuote
end function

function fFinalQuery(strTable)
     strBuildSQL = "INSERT INTO " & strTable & " (" & strBuildFields & ")" & " VALUES (" & strBuildValues & ")"
     fFinalQuery = strBuildSQL
end function
'ABOVE ARE A SERIES OF FUNCITON I'VE WRITTEN FOR SIMPLIFYING INSERT STATEMENT BUILDING
 
     Dim straccessdb, conn, strcon
     strAccessDB = "db1.mdb"
     Set Conn = Server.CreateObject("ADODB.Connection")
     strCon = "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=; DBQ=" & Server.MapPath(strAccessDB)
     conn.Open strCon
     Set rs = Server.createobject("ADODB.recordset")
     dim M_USERNAME
     M_USERNAME = session("user")
       
if request.form("iSaveSingle") = 1 then
     strFieldName = request.form("strDBField")
     strFieldValue = request.form("strFormValue")
     iIsString = request.form("iIsString")
      if len(request.form("checkbox")) >0 then
                    checkbox = True
             else
                       checkbox = False
              end if
     if len(request.form("checkbox2")) >0 then
                    checkbox2 = True
             else
                       checkbox2 = False
              end if
if len(request.form("checkbox3")) >0 then
                    checkbox3 = True
             else
                       checkbox3 = False
              end if
     if len(request.form("checkbox4")) >0 then
                    checkbox4 = True
             else
                       checkbox4 = False
              end if
Response.write("checkbox1 = " & checkbox & "<br>checkbox2=" & checkbox2)
Response.write("checkbox3 = " & checkbox3 & "<br>checkbox4=" & checkbox4)
'Response.End()

       strQuote = ""
     if iIsString = 1 then
          strQuote = "'"
     end if
     strSQL = "UPDATE check "
     strSQL = strSQL & "SET " & strFieldName & " = " & strQuote & strFieldValue & strQuote & " "
'add check boxes
     strSQL = strSQL & ", checkboxfield = " & checkbox & " "
     strSQL = strSQL & ", checkboxfield2 = " & checkbox2 & " "
     strSQL = strSQL & ", checkboxfield3 = " & checkbox3 & " "
     strSQL = strSQL & ", checkboxfield4 = " & checkbox4 & " "
     strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
     '  response.write strsql
'response.end
       conn.execute(strSQL)
     'response.write("<!-- [JAVASCRIPT POPUP WINDOW CODE HERE FOR PDF FILE] -->");
end if
if request.form("iSaveAll") = "1" then
    strSQL = "UPDATE check SET "
     strSQL = strSQL & "dbTextFieldName = '" & request.form("txtTextField") & "'"
     strSQL = strSQL & "dbTextFieldName2 = '" & request.form("txtTextField2") & "'"
'add check boxes
  strSQL = strSQL & ", checkboxfield = " & checkbox & " "
     strSQL = strSQL & ", checkboxfield2 = " & checkbox2 & " "
     strSQL = strSQL & ", checkboxfield3 = " & checkbox3 & " "
     strSQL = strSQL & ", checkboxfield4 = " & checkbox4 & " "
       strSQL = strSQL & " WHERE M_USERNAME = '" & session("user") & "'"
 'read from db
  if request.form("iSaveSingle") <>"1" and request.form("iSaveAll") = "1" Then
strSQL ="SELECT * FROM check  WHERE M_USERNAME = '" & Session("user") & "'"
Set iRS = conn.Execute(strSQL)

   If not iRS.Eof Then
    'get the data
   txtTextField = iRS("txtTextField")
   txtTextField2 = iRS("txtTextField2")
    If  iRS("checkbox") Then checkbox="checked"
   If  iRS("checkbox2") Then checkbox2="checked"
   If  iRS("checkbox3") Then checkbox3="checked"
   If  iRS("checkbox4") Then checkbox4="checked"

  End If
Set iRS = Nothing

End If


 
 
 
 
 
  response.write strsql
response.end
       conn.execute(strSQL)
end if
%>
<%= strSQL %>
<!-- Hidden Form Here -->
<form method="POST" name="frmSaveSingle">
     <input type="hidden" name="iSaveSingle" value="1">
     <input type="hidden" name="strDBField" value="">
     <input type="hidden" name="strFormValue" value="">
     <input type="hidden" name="iIsString" value="0">    
    <input type="hidden" name="checkbox" value="">
    <input type="hidden" name="checkbox2" value="">
    <input type="hidden" name="checkbox3" value="">
    <input type="hidden" name="checkbox4" value="">

</form>


<!-- Real Form Here  [REPLACE BELOW WITH YOUR EXISTING FORM, JUST APPLY THE BUTTON ONCLICK SYNTAX TO THE SAVE BUTTONS]-->
<form name="frmRealForm" method="POST">
     <input type="hidden" name="iSaveAll" value="1">
     <textarea name="txtTextField" value="<%=txtTextField%>"></textarea>
  <input type="checkbox" name="checkbox" value="1" <%=Response.write(checkbox)%>>
<input type="checkbox" name="checkbox2" value="1" <%=Response.write(checkbox2)%>>

   
  <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName','txtTextField',1)">
       <br>
  <textarea  name="txtTextField2" value="<%=txtTextField2%>"></textarea>
  <input type="checkbox" name="checkbox3" value="1" <%=Response.write(checkbox3)%>>
  <input type="checkbox" name="checkbox4" value="1" <%=Response.write(checkbox4)%>>
  <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName2','txtTextField2',1)">

  <br> <input type="submit" value="SAVE ALL">
</form>
0
 

Author Comment

by:Melfeky
ID: 12646294
Here is the putput that i always get even if the checkboxs are empty:
checkbox1 = True
checkbox2=True
checkbox3 = True
checkbox4=True
UPDATE check SET dbTextFieldName2 = 'p' , checkboxfield = True , checkboxfield2 = True , checkboxfield3 = True , checkboxfield4 = True WHERE M_USERNAME = 'dodo'
0
 

Author Comment

by:Melfeky
ID: 12646742
i have found something strange in ur code, u have set the value of the checkbox to 1 nd added this <%=Response.write(checkbox)%>

I have changed it to this but i am still getting the same result:
  <input type="checkbox" name="checkbox" value="<%=Response.write(checkbox)%>">
<input type="checkbox" name="checkbox2" value="<%=Response.write(checkbox2)%>">

Would u tell me why i am getting that result?
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12646846
You would want to do something like this

<input type="checkbox" name="checkbox" <% if checkbox = true then %>checked<% end if %>>
<input type="checkbox" name="checkbox2" <% if checkbox2 = true then %>checked<% end if %>

etc..
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12646857
sry, typo:

<input type="checkbox" name="checkbox" <% if checkbox = true then %>checked<% end if %>>
<input type="checkbox" name="checkbox2" <% if checkbox2 = true then %>checked<% end if %>>
0
 

Author Comment

by:Melfeky
ID: 12646956
AgentSmith007,  nice to see u again :)
u want me to do this change to what code the first code posted in this topic or the last one?
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12647055
Hey Melfeky,

I'd like to see your DB and files in a complete package, if that wouldn't be too much trouble. I can take a look there and post the best possible modification to your code to make everything work smoothly.

Nurbek, the intent of the secondary "Hidden" form is to only submit the values associated with a specific "row" rather than submitting all values. This will reduce HTTP overhead.
0
 

Author Comment

by:Melfeky
ID: 12647092
here is the whole form:
<!--;window.location = 'form1.asp?M_USERNAME=<% response.write (session("user"))%>'; -->
<script language="javascript">
function fSaveSingle(strDBField,strFormValue,iIsString){
     iSubmit = 1;
     if (iSubmit == 1){
          if (document.forms.frmRealForm[strFormValue].value == ""){
               alert("This field cannot be empty.");
               iSubmit = 0;
          }
     }
      if (iSubmit == 1){
          document.forms.frmSaveSingle.strDBField.value = strDBField;
          document.forms.frmSaveSingle.strFormValue.value = document.forms.frmRealForm[strFormValue].value;
          document.forms.frmSaveSingle.iIsString.value = iIsString;
            //below code is added
          document.forms.frmSaveSingle.checkbox.value = document.forms.frmRealForm.checkbox.value;
          document.forms.frmSaveSingle.checkbox2.value = document.forms.frmRealForm.checkbox2.value;
          document.forms.frmSaveSingle.checkbox3.value = document.forms.frmRealForm.checkbox3.value;
          document.forms.frmSaveSingle.checkbox4.value = document.forms.frmRealForm.checkbox4.value;

              document.forms.frmSaveSingle.submit();
     }
}
</script>
<%
'BELOW ARE A SERIES OF FUNCTIONS I'VE WRITTEN FOR SIMPLIFYING INSERT STATEMENT BUILDING
dim strBuildFields,strBuildValues
function fInitQuery()
     strBuildFields = ""
     strBuildValues = ""
end function

function fAddValue(strField,strValue,iString)
     if len(strBuildFields) = 0 then
          strDelimiter = ""
     else
          strDelimiter = ","
     end if
     strBuildFields = strBuildFields & strDelimiter & strField
     'iString should be 1 if it is a string, 0 if it is an integer
     if iString = 1 then
          strQuote = "'"
     else
          strQuote = ""
     end if
     strBuildValues = strBuildValues & strDelimiter & strQuote & strValue & strQuote
end function

function fFinalQuery(strTable)
     strBuildSQL = "INSERT INTO " & strTable & " (" & strBuildFields & ")" & " VALUES (" & strBuildValues & ")"
     fFinalQuery = strBuildSQL
end function
'ABOVE ARE A SERIES OF FUNCITON I'VE WRITTEN FOR SIMPLIFYING INSERT STATEMENT BUILDING
 
     Dim straccessdb, conn, strcon
     strAccessDB = "db1.mdb"
     Set Conn = Server.CreateObject("ADODB.Connection")
     strCon = "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=; DBQ=" & Server.MapPath(strAccessDB)
     conn.Open strCon
     'Set rs = Server.createobject("ADODB.recordset")
     dim M_USERNAME
     M_USERNAME = session("user")
       
if request.form("iSaveSingle") = 1 then
     strFieldName = request.form("strDBField")
     strFieldValue = request.form("strFormValue")
     iIsString = request.form("iIsString")
      if len(request.form("checkbox")) >0 then
                    checkbox = True
             else
                       checkbox = False
              end if
     if len(request.form("checkbox2")) >0 then
                    checkbox2 = True
             else
                       checkbox2 = False
              end if
if len(request.form("checkbox3")) >0 then
                    checkbox3 = True
             else
                       checkbox3 = False
              end if
     if len(request.form("checkbox4")) >0 then
                    checkbox4 = True
             else
                       checkbox4 = False
              end if
Response.write("checkbox1 = " & checkbox & "<br>checkbox2=" & checkbox2)
Response.write("checkbox3 = " & checkbox3 & "<br>checkbox4=" & checkbox4)
'Response.End()

       strQuote = ""
     if iIsString = 1 then
          strQuote = "'"
     end if
     strSQL = "UPDATE check "
     strSQL = strSQL & "SET " & strFieldName & " = " & strQuote & strFieldValue & strQuote & " "
'add check boxes
     strSQL = strSQL & ", checkboxfield = " & checkbox & " "
     strSQL = strSQL & ", checkboxfield2 = " & checkbox2 & " "
     strSQL = strSQL & ", checkboxfield3 = " & checkbox3 & " "
     strSQL = strSQL & ", checkboxfield4 = " & checkbox4 & " "
     strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
     '  response.write strsql
'response.end
       conn.execute(strSQL)
     'response.write("<!-- [JAVASCRIPT POPUP WINDOW CODE HERE FOR PDF FILE] -->");
end if
if request.form("iSaveAll") = "1" then
    strSQL = "UPDATE check SET "
     strSQL = strSQL & "dbTextFieldName = '" & request.form("txtTextField") & "'"
     strSQL = strSQL & "dbTextFieldName2 = '" & request.form("txtTextField2") & "'"
'add check boxes
     strSQL = strSQL & ", checkboxfield = " & checkbox & " "
     strSQL = strSQL & ", checkboxfield2 = " & checkbox2 & " "
     strSQL = strSQL & ", checkboxfield3 = " & checkbox3 & " "
     strSQL = strSQL & ", checkboxfield4 = " & checkbox4 & " "
       strSQL = strSQL & " WHERE M_USERNAME = '" & session("user") & "'"
 'read from db
  if request.form("iSaveSingle") <>"1" and request.form("iSaveAll") = "1" Then
strSQL ="SELECT * FROM check  WHERE M_USERNAME = '" & Session("user") & "'"
Set iRS = conn.Execute(strSQL)

   If not iRS.Eof Then
    'get the data
   txtTextField = iRS("txtTextField")
   txtTextField2 = iRS("txtTextField2")
    If  iRS("checkbox") Then checkbox="checked"
   If  iRS("checkbox2") Then checkbox2="checked"
   If  iRS("checkbox3") Then checkbox3="checked"
   If  iRS("checkbox4") Then checkbox4="checked"

  End If
Set iRS = Nothing

End If


 
 
 
 
 
  response.write strsql
response.end
       conn.execute(strSQL)
end if
%>
<%= strSQL %>
<!-- Hidden Form Here -->
<form method="POST" name="frmSaveSingle">
     <input type="hidden" name="iSaveSingle" value="1">
     <input type="hidden" name="strDBField" value="">
     <input type="hidden" name="strFormValue" value="">
     <input type="hidden" name="iIsString" value="0">    
    <input type="hidden" name="checkbox" value="">
    <input type="hidden" name="checkbox2" value="">
    <input type="hidden" name="checkbox3" value="">
    <input type="hidden" name="checkbox4" value="">

</form>


<!-- Real Form Here  [REPLACE BELOW WITH YOUR EXISTING FORM, JUST APPLY THE BUTTON ONCLICK SYNTAX TO THE SAVE BUTTONS]-->
<form name="frmRealForm" method="POST">
     <input type="hidden" name="iSaveAll" value="1">
     <textarea name="txtTextField" value="<%=txtTextField%>"></textarea>
<input type="checkbox" name="checkbox" <% if checkbox = true then %>checked<% end if %>>
<input type="checkbox" name="checkbox2" <% if checkbox2 = true then %>checked<% end if %>>
   
  <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName','txtTextField',1)">
       <br>
  <textarea  name="txtTextField2" value="<%=txtTextField2%>"></textarea>
<input type="checkbox" name="checkbox3" <% if checkbox3 = true then %>checked<% end if %>>
<input type="checkbox" name="checkbox4" <% if checkbox4 = true then %>checked<% end if %>>  <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName2','txtTextField2',1)">

  <br> <input type="submit" value="SAVE ALL">
</form>
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12647097
I assume what you're trying to do is associate a couple checkboxes with each "single-save" text field, is that correct melfeky? BTW, to send me all that stuff, forward it to agent.smith.78@gmail.com
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12647132
OK, What fields in the Database represent your checkboxes? What type of fields are they? Bit, Integer, Text?
0
 

Author Comment

by:Melfeky
ID: 12647133
database:

field name              datatype                     format

checkboxfield          yes/no                       true/false
checkboxfield2        yes/no                        true/false
checkboxfield3        yes/no                        true/false
checkboxfield4        yes/no                        true/false
txtTextField             text
txtTextField2           text

0
 

Author Comment

by:Melfeky
ID: 12647191
i have sent u an email with the files, thanks.
0
 

Author Comment

by:Melfeky
ID: 12647199
i got a failure when sending the email,
isn't it    :   agent.smith.78@gmail.com
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12647294
ya:
agent.smith.78@gmail.com

try sending to:
scott.tompkins@gmail.com
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12647317
melfeky,

make all your checkboxes look like this:

<input type="checkbox" value=1 name="checkbox" <% if checkbox = true then %>checked<% end if %>>
<input type="checkbox" value=1 name="checkbox2" <% if checkbox2 = true then %>checked<% end if %>>
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12647351
ALSO,

change your ASP-side checkbox checking to this:

      if request.form("checkbox") = 1 then
            checkbox = True
      else
            checkbox = False
      end if
      if request.form("checkbox2") = 1 then
            checkbox2 = True
      else
            checkbox2 = False
      end if
      if request.form("checkbox3") = 1 then
            checkbox3 = True
      else
            checkbox3 = False
      end if
      if request.form("checkbox4") = 1 then
            checkbox4 = True
      else
            checkbox4 = False
      end if
0
 

Author Comment

by:Melfeky
ID: 12647389
i guess your mail don't accept the large files , so i sent u the file only without the db.
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12647423
The account accepts attachments up to 10 MB, but maybe it is stripping zip files out...who knows...did you try the above mentioned changes?
0
 

Author Comment

by:Melfeky
ID: 12647436
yes i have tried them but i got this error:
Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: '[string: "on"]'
/pdf1/formtest.asp, line 68


0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12647454
what is on line 68?
0
 

Author Comment

by:Melfeky
ID: 12647500
if request.form("checkbox") = 1 then
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12647511
Did you add the " value=1" parameter to your HTML checkbox inputs?
0
 

Author Comment

by:Melfeky
ID: 12647532
no, should i?
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12647598
yep, i posted it above:

make all your checkboxes look like this:

<input type="checkbox" value=1 name="checkbox" <% if checkbox = true then %>checked<% end if %>>
<input type="checkbox" value=1 name="checkbox2" <% if checkbox2 = true then %>checked<% end if %>>
0
 

Author Comment

by:Melfeky
ID: 12647654
Still getting the same error:
Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: '[string: "on"]'
/pdf1/formtest.asp, line 68
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12647666
Can you repost your entire code again please?
0
 

Author Comment

by:Melfeky
ID: 12647736
<!--;window.location = 'form1.asp?M_USERNAME=<% response.write (session("user"))%>'; -->
<script language="javascript">
function fSaveSingle(strDBField,strFormValue,iIsString){
     iSubmit = 1;
     if (iSubmit == 1){
          if (document.forms.frmRealForm[strFormValue].value == ""){
               alert("This field cannot be empty.");
               iSubmit = 0;
          }
     }
      if (iSubmit == 1){
          document.forms.frmSaveSingle.strDBField.value = strDBField;
          document.forms.frmSaveSingle.strFormValue.value = document.forms.frmRealForm[strFormValue].value;
          document.forms.frmSaveSingle.iIsString.value = iIsString;
            //below code is added
          document.forms.frmSaveSingle.checkbox.value = document.forms.frmRealForm.checkbox.value;
          document.forms.frmSaveSingle.checkbox2.value = document.forms.frmRealForm.checkbox2.value;
          document.forms.frmSaveSingle.checkbox3.value = document.forms.frmRealForm.checkbox3.value;
          document.forms.frmSaveSingle.checkbox4.value = document.forms.frmRealForm.checkbox4.value;

              document.forms.frmSaveSingle.submit();
     }
}
</script>
<%
'BELOW ARE A SERIES OF FUNCTIONS I'VE WRITTEN FOR SIMPLIFYING INSERT STATEMENT BUILDING
dim strBuildFields,strBuildValues
function fInitQuery()
     strBuildFields = ""
     strBuildValues = ""
end function

function fAddValue(strField,strValue,iString)
     if len(strBuildFields) = 0 then
          strDelimiter = ""
     else
          strDelimiter = ","
     end if
     strBuildFields = strBuildFields & strDelimiter & strField
     'iString should be 1 if it is a string, 0 if it is an integer
     if iString = 1 then
          strQuote = "'"
     else
          strQuote = ""
     end if
     strBuildValues = strBuildValues & strDelimiter & strQuote & strValue & strQuote
end function

function fFinalQuery(strTable)
     strBuildSQL = "INSERT INTO " & strTable & " (" & strBuildFields & ")" & " VALUES (" & strBuildValues & ")"
     fFinalQuery = strBuildSQL
end function
'ABOVE ARE A SERIES OF FUNCITON I'VE WRITTEN FOR SIMPLIFYING INSERT STATEMENT BUILDING
 
     Dim straccessdb, conn, strcon
     strAccessDB = "db1.mdb"
     Set Conn = Server.CreateObject("ADODB.Connection")
     strCon = "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=; DBQ=" & Server.MapPath(strAccessDB)
     conn.Open strCon
     'Set rs = Server.createobject("ADODB.recordset")
     dim M_USERNAME
     M_USERNAME = session("user")
       
if request.form("iSaveSingle") = 1 then
     strFieldName = request.form("strDBField")
     strFieldValue = request.form("strFormValue")
     iIsString = request.form("iIsString")
if request.form("checkbox") = 1 then
          checkbox = True
     else
          checkbox = False
     end if
     if request.form("checkbox2") = 1 then
          checkbox2 = True
     else
          checkbox2 = False
     end if
     if request.form("checkbox3") = 1 then
          checkbox3 = True
     else
          checkbox3 = False
     end if
     if request.form("checkbox4") = 1 then
          checkbox4 = True
     else
          checkbox4 = False
     end if
Response.write("checkbox1 = " & checkbox & "<br>checkbox2=" & checkbox2)
Response.write("checkbox3 = " & checkbox3 & "<br>checkbox4=" & checkbox4)
'Response.End()

       strQuote = ""
     if iIsString = 1 then
          strQuote = "'"
     end if
     strSQL = "UPDATE check "
     strSQL = strSQL & "SET " & strFieldName & " = " & strQuote & strFieldValue & strQuote & " "
'add check boxes
     strSQL = strSQL & ", checkboxfield = " & checkbox & " "
     strSQL = strSQL & ", checkboxfield2 = " & checkbox2 & " "
     strSQL = strSQL & ", checkboxfield3 = " & checkbox3 & " "
     strSQL = strSQL & ", checkboxfield4 = " & checkbox4 & " "
     strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
     '  response.write strsql
'response.end
       conn.execute(strSQL)
     'response.write("<!-- [JAVASCRIPT POPUP WINDOW CODE HERE FOR PDF FILE] -->");
end if
if request.form("iSaveAll") = "1" then
    strSQL = "UPDATE check SET "
     strSQL = strSQL & "dbTextFieldName = '" & request.form("txtTextField") & "'"
     strSQL = strSQL & "dbTextFieldName2 = '" & request.form("txtTextField2") & "'"
'add check boxes
     strSQL = strSQL & ", checkboxfield = " & checkbox & " "
     strSQL = strSQL & ", checkboxfield2 = " & checkbox2 & " "
     strSQL = strSQL & ", checkboxfield3 = " & checkbox3 & " "
     strSQL = strSQL & ", checkboxfield4 = " & checkbox4 & " "
       strSQL = strSQL & " WHERE M_USERNAME = '" & session("user") & "'"
 'read from db
  if request.form("iSaveSingle") <>"1" and request.form("iSaveAll") = "1" Then
strSQL ="SELECT * FROM check  WHERE M_USERNAME = '" & Session("user") & "'"
Set iRS = conn.Execute(strSQL)

   If not iRS.Eof Then
    'get the data
   txtTextField = iRS("txtTextField")
   txtTextField2 = iRS("txtTextField2")
    If  iRS("checkbox") Then checkbox="checked"
   If  iRS("checkbox2") Then checkbox2="checked"
   If  iRS("checkbox3") Then checkbox3="checked"
   If  iRS("checkbox4") Then checkbox4="checked"

  End If
Set iRS = Nothing

End If


 
 
 
 
 
  response.write strsql
response.end
       conn.execute(strSQL)
end if
%>
<%= strSQL %>
<!-- Hidden Form Here -->
<form method="POST" name="frmSaveSingle">
     <input type="hidden" name="iSaveSingle" value="1">
     <input type="hidden" name="strDBField" value="">
     <input type="hidden" name="strFormValue" value="">
     <input type="hidden" name="iIsString" value="0">    
    <input type="hidden" name="checkbox" value="">
    <input type="hidden" name="checkbox2" value="">
    <input type="hidden" name="checkbox3" value="">
    <input type="hidden" name="checkbox4" value="">

</form>


<!-- Real Form Here  [REPLACE BELOW WITH YOUR EXISTING FORM, JUST APPLY THE BUTTON ONCLICK SYNTAX TO THE SAVE BUTTONS]-->
<form name="frmRealForm" method="POST">
     <input type="hidden" name="iSaveAll" value="1">
     <textarea name="txtTextField" value="<%=txtTextField%>"></textarea>
<input type="checkbox" name="checkbox" <% if checkbox = true then %>checked<% end if %>>
<input type="checkbox" name="checkbox2" <% if checkbox2 = true then %>checked<% end if %>>
   
  <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName','txtTextField',1)">
       <br>
  <textarea  name="txtTextField2" value="<%=txtTextField2%>"></textarea>
<input type="checkbox" name="checkbox3" <% if checkbox3 = true then %>checked<% end if %>>
<input type="checkbox" name="checkbox4" <% if checkbox4 = true then %>checked<% end if %>>
 <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName2','txtTextField2',1)">

  <br> <input type="submit" value="SAVE ALL">
</form>
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12647790
ok, replace it with this:

I have made changes in several areas throughout, so you should probably just replace the whole thing.

<!--;window.location = 'form1.asp?M_USERNAME=<% response.write (session("user"))%>'; -->
<script language="javascript">
function fSaveSingle(strDBField,strFormValue,iIsString){
     iSubmit = 1;
     if (iSubmit == 1){
          if (document.forms.frmRealForm[strFormValue].value == ""){
               alert("This field cannot be empty.");
               iSubmit = 0;
          }
     }
      if (iSubmit == 1){
          document.forms.frmSaveSingle.strDBField.value = strDBField;
          document.forms.frmSaveSingle.strFormValue.value = document.forms.frmRealForm[strFormValue].value;
          document.forms.frmSaveSingle.iIsString.value = iIsString;
            //below code is added
            document.forms.frmSaveSingle.checkbox.value = 0;
            document.forms.frmSaveSingle.checkbox2.value = 0;
            document.forms.frmSaveSingle.checkbox3.value = 0;
            document.forms.frmSaveSingle.checkbox4.value = 0;
            if (document.forms.frmRealform.checkbox.checked == true){
                  document.forms.frmSaveSingle.checkbox.value = 1;
            }
            if (document.forms.frmRealform.checkbox2.checked == true){
                  document.forms.frmSaveSingle.checkbox2.value = 1;
            }            
            if (document.forms.frmRealform3.checkbox.checked == true){
                  document.forms.frmSaveSingle.checkbox3.value = 1;
            }            
            if (document.forms.frmRealform.checkbox4.checked == true){
                  document.forms.frmSaveSingle.checkbox4.value = 1;
            }            
        document.forms.frmSaveSingle.submit();
     }
}
</script>
<%
'BELOW ARE A SERIES OF FUNCTIONS I'VE WRITTEN FOR SIMPLIFYING INSERT STATEMENT BUILDING
dim strBuildFields,strBuildValues
function fInitQuery()
     strBuildFields = ""
     strBuildValues = ""
end function

function fAddValue(strField,strValue,iString)
     if len(strBuildFields) = 0 then
          strDelimiter = ""
     else
          strDelimiter = ","
     end if
     strBuildFields = strBuildFields & strDelimiter & strField
     'iString should be 1 if it is a string, 0 if it is an integer
     if iString = 1 then
          strQuote = "'"
     else
          strQuote = ""
     end if
     strBuildValues = strBuildValues & strDelimiter & strQuote & strValue & strQuote
end function

function fFinalQuery(strTable)
     strBuildSQL = "INSERT INTO " & strTable & " (" & strBuildFields & ")" & " VALUES (" & strBuildValues & ")"
     fFinalQuery = strBuildSQL
end function
'ABOVE ARE A SERIES OF FUNCITON I'VE WRITTEN FOR SIMPLIFYING INSERT STATEMENT BUILDING
 
     Dim straccessdb, conn, strcon
     strAccessDB = "db1.mdb"
     Set Conn = Server.CreateObject("ADODB.Connection")
     strCon = "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=; DBQ=" & Server.MapPath(strAccessDB)
     conn.Open strCon
     'Set rs = Server.createobject("ADODB.recordset")
     dim M_USERNAME
     M_USERNAME = session("user")

if cint(request.form("checkbox")) = 1 then
      checkbox = True
else
      checkbox = False
end if

if cint(request.form("checkbox2")) = 1 then
      checkbox2 = True
else
      checkbox2 = False
end if

if cint(request.form("checkbox3")) = 1 then
      checkbox3 = True
else
      checkbox3 = False
end if

if cint(request.form("checkbox4")) = 1 then
      checkbox4 = True
else
      checkbox4 = False
end if

Response.write("checkbox1 = " & checkbox & "<br>checkbox2=" & checkbox2)
Response.write("checkbox3 = " & checkbox3 & "<br>checkbox4=" & checkbox4)

       
if request.form("iSaveSingle") = 1 then
     strFieldName = request.form("strDBField")
     strFieldValue = request.form("strFormValue")
     iIsString = request.form("iIsString")
'Response.End()

      strQuote = ""
     if iIsString = 1 then
          strQuote = "'"
     end if
     strSQL = "UPDATE check "
     strSQL = strSQL & "SET " & strFieldName & " = " & strQuote & strFieldValue & strQuote & " "
'add check boxes
     strSQL = strSQL & ", checkboxfield = " & checkbox & " "
     strSQL = strSQL & ", checkboxfield2 = " & checkbox2 & " "
     strSQL = strSQL & ", checkboxfield3 = " & checkbox3 & " "
     strSQL = strSQL & ", checkboxfield4 = " & checkbox4 & " "
     strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
     '  response.write strsql
'response.end
      conn.execute(strSQL)
     'response.write("<!-- [JAVASCRIPT POPUP WINDOW CODE HERE FOR PDF FILE] -->");
end if
if request.form("iSaveAll") = "1" then
    strSQL = "UPDATE check SET "
     strSQL = strSQL & "dbTextFieldName = '" & request.form("txtTextField") & "'"
     strSQL = strSQL & "dbTextFieldName2 = '" & request.form("txtTextField2") & "'"
'add check boxes
     strSQL = strSQL & ", checkboxfield = " & checkbox & " "
     strSQL = strSQL & ", checkboxfield2 = " & checkbox2 & " "
     strSQL = strSQL & ", checkboxfield3 = " & checkbox3 & " "
     strSQL = strSQL & ", checkboxfield4 = " & checkbox4 & " "
      strSQL = strSQL & " WHERE M_USERNAME = '" & session("user") & "'"
 'read from db
  if request.form("iSaveSingle") <>"1" and request.form("iSaveAll") = "1" Then
strSQL ="SELECT * FROM check  WHERE M_USERNAME = '" & Session("user") & "'"
Set iRS = conn.Execute(strSQL)

   If not iRS.Eof Then
    'get the data
   txtTextField = iRS("txtTextField")
   txtTextField2 = iRS("txtTextField2")
    If  iRS("checkbox") Then checkbox="checked"
   If  iRS("checkbox2") Then checkbox2="checked"
   If  iRS("checkbox3") Then checkbox3="checked"
   If  iRS("checkbox4") Then checkbox4="checked"

  End If
Set iRS = Nothing

End If


 
 
 
 
 
  response.write strsql
response.end
      conn.execute(strSQL)
end if
%>
<%= strSQL %>
<!-- Hidden Form Here -->
<form method="POST" name="frmSaveSingle">
     <input type="hidden" name="iSaveSingle" value="1">
     <input type="hidden" name="strDBField" value="">
     <input type="hidden" name="strFormValue" value="">
     <input type="hidden" name="iIsString" value="0">    
    <input type="hidden" name="checkbox" value="">
    <input type="hidden" name="checkbox2" value="">
    <input type="hidden" name="checkbox3" value="">
    <input type="hidden" name="checkbox4" value="">

</form>


<!-- Real Form Here  [REPLACE BELOW WITH YOUR EXISTING FORM, JUST APPLY THE BUTTON ONCLICK SYNTAX TO THE SAVE BUTTONS]-->
<form name="frmRealForm" method="POST">
     <input type="hidden" name="iSaveAll" value="1">
     <textarea name="txtTextField" value="<%=txtTextField%>"></textarea>
<input type="checkbox" value="1" name="checkbox" <% if checkbox = true then %>checked<% end if %>>
<input type="checkbox" value="1" name="checkbox2" <% if checkbox2 = true then %>checked<% end if %>>
   
  <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName','txtTextField',1)">
       <br>
  <textarea  name="txtTextField2" value="<%=txtTextField2%>"></textarea>
<input type="checkbox" value="1" name="checkbox3" <% if checkbox3 = true then %>checked<% end if %>>
<input type="checkbox" value="1" name="checkbox4" <% if checkbox4 = true then %>checked<% end if %>>
 <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName2','txtTextField2',1)">

  <br> <input type="submit" value="SAVE ALL">
</form>
0
 

Author Comment

by:Melfeky
ID: 12648048
i have done that but when i opened the page and entered data and click the save button nothing happened , and a yellow icon is displaayed down t the status bar telling this:
line 20
char 11
error'document.forms.frmreal.checkbox' is null or not an object
code:0
0
 

Author Comment

by:Melfeky
ID: 12648391
i don't know why i m getting this error, do u?
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12648468
try replacing the between the <script> tags with this:

<script language="javascript">
function fSaveSingle(strDBField,strFormValue,iIsString){
     iSubmit = 1;
     if (iSubmit == 1){
          if (document.forms.frmRealForm[strFormValue].value == ""){
               alert("This field cannot be empty.");
               iSubmit = 0;
          }
     }
      if (iSubmit == 1){
          document.forms.frmSaveSingle.strDBField.value = strDBField;
          document.forms.frmSaveSingle.strFormValue.value = document.forms.frmRealForm[strFormValue].value;
          document.forms.frmSaveSingle.iIsString.value = iIsString;
            //below code is added
            document.forms.frmSaveSingle.checkbox.value = 0;
            document.forms.frmSaveSingle.checkbox2.value = 0;
            document.forms.frmSaveSingle.checkbox3.value = 0;
            document.forms.frmSaveSingle.checkbox4.value = 0;
            if (document.forms.frmRealForm.checkbox.checked == true){
                  document.forms.frmSaveSingle.checkbox.value = 1;
            }
            if (document.forms.frmRealForm.checkbox2.checked == true){
                  document.forms.frmSaveSingle.checkbox2.value = 1;
            }            
            if (document.forms.frmRealForm.checkbox3.checked == true){
                  document.forms.frmSaveSingle.checkbox3.value = 1;
            }            
            if (document.forms.frmRealForm.checkbox4.checked == true){
                  document.forms.frmSaveSingle.checkbox4.value = 1;
            }            
        document.forms.frmSaveSingle.submit();
     }
}
</script>
0
 

Author Comment

by:Melfeky
ID: 12648521
when i did that the error disabeared but no data is saved into the db but i got this sql statment:
checkbox = True
checkbox2=True
checkbox3 = False
checkbox4=False
UPDATE check SET dbTextFieldName = 'gogo' , checkboxfield = True , checkboxfield2 = True , checkboxfield3 = False , checkboxfield4 = False WHERE M_USERNAME = 'dodo'UPDATE check SET dbTextFieldName = 'gogo' , checkboxfield = True , checkboxfield2 = True , checkboxfield3 = False , checkboxfield4 = False WHERE M_USERNAME = 'dodo'

which is right as this is what i have added into the form.
0
 

Author Comment

by:Melfeky
ID: 12648634
i removed <%strsql%>
so now it is just :
checkbox = False
checkbox2=Truecheckbox3 = True
checkbox4=TrueUPDATE check SET dbTextFieldName2 = 'x' , checkboxfield = False , checkboxfield2 = True , checkboxfield3 = True , checkboxfield4 = True WHERE M_USERNAME = 'dodo'

so everything is fine exept that it is not saved in the db and also the stored value is not displayed in the form either.
0
 

Author Comment

by:Melfeky
ID: 12648653
i have changed this part to match the name of the fields stored in the db:
   If not iRS.Eof Then
    'get the data
   txtTextField = iRS("txtTextField")
   txtTextField2 = iRS("txtTextField2")
    If  iRS("checkboxfield") Then checkbox="checked"
   If  iRS("checkboxfield2") Then checkbox2="checked"
   If  iRS("checkboxfield3") Then checkbox3="checked"
   If  iRS("checkboxfield4") Then checkbox4="checked"

  End If
0
 

Author Comment

by:Melfeky
ID: 12648747
so now when i click on the save all button i get no errors but stillno data is saved in the db.
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12648951
ok, i've rewritten a lot of this to be a bit cleaner...try replacing all with this:

<!--;window.location = 'form1.asp?M_USERNAME=<% response.write (session("user"))%>'; -->
<script language="javascript">
function fSaveSingle(strDBField,strFormValue,iIsString){
     iSubmit = 1;
     if (iSubmit == 1){
          if (document.forms.frmRealForm[strFormValue].value == ""){
               alert("This field cannot be empty.");
               iSubmit = 0;
          }
     }
      if (iSubmit == 1){
          document.forms.frmSaveSingle.strDBField.value = strDBField;
          document.forms.frmSaveSingle.strFormValue.value = document.forms.frmRealForm[strFormValue].value;
          document.forms.frmSaveSingle.iIsString.value = iIsString;
            //below code is added
            document.forms.frmSaveSingle.checkbox.value = 0;
            document.forms.frmSaveSingle.checkbox2.value = 0;
            document.forms.frmSaveSingle.checkbox3.value = 0;
            document.forms.frmSaveSingle.checkbox4.value = 0;
            if (document.forms.frmRealForm.checkbox.checked == true){
                  document.forms.frmSaveSingle.checkbox.value = 1;
            }
            if (document.forms.frmRealForm.checkbox2.checked == true){
                  document.forms.frmSaveSingle.checkbox2.value = 1;
            }            
            if (document.forms.frmRealForm.checkbox3.checked == true){
                  document.forms.frmSaveSingle.checkbox3.value = 1;
            }            
            if (document.forms.frmRealForm.checkbox4.checked == true){
                  document.forms.frmSaveSingle.checkbox4.value = 1;
            }            
        document.forms.frmSaveSingle.submit();
     }
}
</script>
<%
'Declare connection object
 Dim straccessdb, conn, strcon
 strAccessDB = "db1.mdb"
 Set Conn = Server.CreateObject("ADODB.Connection")
 strCon = "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=; DBQ=" & Server.MapPath(strAccessDB)
 conn.Open strCon
 'Set rs = Server.createobject("ADODB.recordset")
'Set current user
dim M_USERNAME
M_USERNAME = session("user")

'Set checkbox values
checkbox = False
checkbox2 = False
checkbox3 = False
checkbox4 = False
if cint(request.form("checkbox")) = 1 then
      checkbox = True
end if

if cint(request.form("checkbox2")) = 1 then
      checkbox2 = True
end if

if cint(request.form("checkbox3")) = 1 then
      checkbox3 = True
end if

if cint(request.form("checkbox4")) = 1 then
      checkbox4 = True
end if

Response.write("checkbox1 = " & checkbox & "<br>checkbox2=" & checkbox2)
Response.write("checkbox3 = " & checkbox3 & "<br>checkbox4=" & checkbox4)
       
if request.form("iSaveSingle") = 1 then
      'Saving a single "row"
     strFieldName = request.form("strDBField")
     strFieldValue = request.form("strFormValue")
     iIsString = request.form("iIsString")
'Response.End()
       strQuote = ""
     if iIsString = 1 then
          strQuote = "'"
     end if
     strSQL = "UPDATE check "
     strSQL = strSQL & "SET " & strFieldName & " = " & strQuote & strFieldValue & strQuote & " "
'add check boxes
     strSQL = strSQL & ", checkboxfield = " & checkbox & " "
     strSQL = strSQL & ", checkboxfield2 = " & checkbox2 & " "
     strSQL = strSQL & ", checkboxfield3 = " & checkbox3 & " "
     strSQL = strSQL & ", checkboxfield4 = " & checkbox4 & " "
     strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
     '  response.write strsql
'response.end
      conn.execute(strSQL)
     'response.write("<!-- [JAVASCRIPT POPUP WINDOW CODE HERE FOR PDF FILE] -->");
end if

if request.form("iSaveAll") = "1" then
      'Saving entire form
      strSQL = "UPDATE check SET "
      strSQL = strSQL & "dbTextFieldName = '" & request.form("txtTextField") & "'"
      strSQL = strSQL & "dbTextFieldName2 = '" & request.form("txtTextField2") & "'"
      'add check boxes
      strSQL = strSQL & ", checkboxfield = " & checkbox & " "
      strSQL = strSQL & ", checkboxfield2 = " & checkbox2 & " "
      strSQL = strSQL & ", checkboxfield3 = " & checkbox3 & " "
      strSQL = strSQL & ", checkboxfield4 = " & checkbox4 & " "
      strSQL = strSQL & " WHERE M_USERNAME = '" & session("user") & "'"
      conn.execute(strSQL)
End If


'read from db
strSQL ="SELECT * FROM check  WHERE M_USERNAME = '" & Session("user") & "'"
Set oRS = conn.Execute(strSQL)
checkbox = False
checkbox2 = False
checkbox3 = False
checkbox4 = False
while not iRS.Eof Then
      'get the data
      txtTextField = iRS("txtTextField")
      txtTextField2 = iRS("txtTextField2")
      If  oRS("checkbox") Then
            checkbox=true
      end if
      If  oRS("checkbox2") Then
            checkbox2=true
      end if
      If  oRS("checkbox3") Then
            checkbox3="checked"
      end if
      If  oRS("checkbox4") Then
            checkbox4="checked"
      end if
      oRS.MoveNext
wend
oRS.close
set oRS = nothing
%>
<!-- Hidden Form Here -->
<form method="POST" name="frmSaveSingle">
     <input type="hidden" name="iSaveSingle" value="1">
     <input type="hidden" name="strDBField" value="">
     <input type="hidden" name="strFormValue" value="">
     <input type="hidden" name="iIsString" value="0">    
    <input type="hidden" name="checkbox" value="">
    <input type="hidden" name="checkbox2" value="">
    <input type="hidden" name="checkbox3" value="">
    <input type="hidden" name="checkbox4" value="">

</form>


<!-- Real Form Here  [REPLACE BELOW WITH YOUR EXISTING FORM, JUST APPLY THE BUTTON ONCLICK SYNTAX TO THE SAVE BUTTONS]-->
<form name="frmRealForm" method="POST">
     <input type="hidden" name="iSaveAll" value="1">
     <textarea name="txtTextField" value="<%=txtTextField%>"></textarea>
      <input type="checkbox" value="1" name="checkbox" <% if checkbox = true then %>checked<% end if %>>
      <input type="checkbox" value="1" name="checkbox2" <% if checkbox2 = true then %>checked<% end if %>>
   
  <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName','txtTextField',1)">
       <br>
  <textarea  name="txtTextField2" value="<%=txtTextField2%>"></textarea>
<input type="checkbox" value="1" name="checkbox3" <% if checkbox3 = true then %>checked<% end if %>>
<input type="checkbox" value="1" name="checkbox4" <% if checkbox4 = true then %>checked<% end if %>>
 <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName2','txtTextField2',1)">

  <br> <input type="submit" value="SAVE ALL">
</form>
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12648968
Sry, typo...this instead:

<!--;window.location = 'form1.asp?M_USERNAME=<% response.write (session("user"))%>'; -->
<script language="javascript">
function fSaveSingle(strDBField,strFormValue,iIsString){
     iSubmit = 1;
     if (iSubmit == 1){
          if (document.forms.frmRealForm[strFormValue].value == ""){
               alert("This field cannot be empty.");
               iSubmit = 0;
          }
     }
      if (iSubmit == 1){
          document.forms.frmSaveSingle.strDBField.value = strDBField;
          document.forms.frmSaveSingle.strFormValue.value = document.forms.frmRealForm[strFormValue].value;
          document.forms.frmSaveSingle.iIsString.value = iIsString;
            //below code is added
            document.forms.frmSaveSingle.checkbox.value = 0;
            document.forms.frmSaveSingle.checkbox2.value = 0;
            document.forms.frmSaveSingle.checkbox3.value = 0;
            document.forms.frmSaveSingle.checkbox4.value = 0;
            if (document.forms.frmRealForm.checkbox.checked == true){
                  document.forms.frmSaveSingle.checkbox.value = 1;
            }
            if (document.forms.frmRealForm.checkbox2.checked == true){
                  document.forms.frmSaveSingle.checkbox2.value = 1;
            }            
            if (document.forms.frmRealForm.checkbox3.checked == true){
                  document.forms.frmSaveSingle.checkbox3.value = 1;
            }            
            if (document.forms.frmRealForm.checkbox4.checked == true){
                  document.forms.frmSaveSingle.checkbox4.value = 1;
            }            
        document.forms.frmSaveSingle.submit();
     }
}
</script>
<%
'Declare connection object
 Dim straccessdb, conn, strcon
 strAccessDB = "db1.mdb"
 Set Conn = Server.CreateObject("ADODB.Connection")
 strCon = "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=; DBQ=" & Server.MapPath(strAccessDB)
 conn.Open strCon
 'Set rs = Server.createobject("ADODB.recordset")
'Set current user
dim M_USERNAME
M_USERNAME = session("user")

'Set checkbox values
checkbox = False
checkbox2 = False
checkbox3 = False
checkbox4 = False
if cint(request.form("checkbox")) = 1 then
      checkbox = True
end if

if cint(request.form("checkbox2")) = 1 then
      checkbox2 = True
end if

if cint(request.form("checkbox3")) = 1 then
      checkbox3 = True
end if

if cint(request.form("checkbox4")) = 1 then
      checkbox4 = True
end if

Response.write("checkbox1 = " & checkbox & "<br>checkbox2=" & checkbox2)
Response.write("checkbox3 = " & checkbox3 & "<br>checkbox4=" & checkbox4)
       
if request.form("iSaveSingle") = 1 then
      'Saving a single "row"
     strFieldName = request.form("strDBField")
     strFieldValue = request.form("strFormValue")
     iIsString = request.form("iIsString")
'Response.End()
       strQuote = ""
     if iIsString = 1 then
          strQuote = "'"
     end if
     strSQL = "UPDATE check "
     strSQL = strSQL & "SET " & strFieldName & " = " & strQuote & strFieldValue & strQuote & " "
'add check boxes
     strSQL = strSQL & ", checkboxfield = " & checkbox & " "
     strSQL = strSQL & ", checkboxfield2 = " & checkbox2 & " "
     strSQL = strSQL & ", checkboxfield3 = " & checkbox3 & " "
     strSQL = strSQL & ", checkboxfield4 = " & checkbox4 & " "
     strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
     '  response.write strsql
'response.end
      conn.execute(strSQL)
     'response.write("<!-- [JAVASCRIPT POPUP WINDOW CODE HERE FOR PDF FILE] -->");
end if

if request.form("iSaveAll") = "1" then
      'Saving entire form
      strSQL = "UPDATE check SET "
      strSQL = strSQL & "dbTextFieldName = '" & request.form("txtTextField") & "'"
      strSQL = strSQL & "dbTextFieldName2 = '" & request.form("txtTextField2") & "'"
      'add check boxes
      strSQL = strSQL & ", checkboxfield = " & checkbox & " "
      strSQL = strSQL & ", checkboxfield2 = " & checkbox2 & " "
      strSQL = strSQL & ", checkboxfield3 = " & checkbox3 & " "
      strSQL = strSQL & ", checkboxfield4 = " & checkbox4 & " "
      strSQL = strSQL & " WHERE M_USERNAME = '" & session("user") & "'"
      conn.execute(strSQL)
End If


'read from db
strSQL ="SELECT * FROM check  WHERE M_USERNAME = '" & Session("user") & "'"
Set oRS = conn.Execute(strSQL)
checkbox = False
checkbox2 = False
checkbox3 = False
checkbox4 = False
while not oRS.Eof Then
      'get the data
      txtTextField = iRS("txtTextField")
      txtTextField2 = iRS("txtTextField2")
      If  oRS("checkbox") Then
            checkbox=true
      end if
      If  oRS("checkbox2") Then
            checkbox2=true
      end if
      If  oRS("checkbox3") Then
            checkbox3="checked"
      end if
      If  oRS("checkbox4") Then
            checkbox4="checked"
      end if
      oRS.MoveNext
wend
oRS.close
set oRS = nothing
%>
<!-- Hidden Form Here -->
<form method="POST" name="frmSaveSingle">
     <input type="hidden" name="iSaveSingle" value="1">
     <input type="hidden" name="strDBField" value="">
     <input type="hidden" name="strFormValue" value="">
     <input type="hidden" name="iIsString" value="0">    
    <input type="hidden" name="checkbox" value="">
    <input type="hidden" name="checkbox2" value="">
    <input type="hidden" name="checkbox3" value="">
    <input type="hidden" name="checkbox4" value="">

</form>


<!-- Real Form Here  [REPLACE BELOW WITH YOUR EXISTING FORM, JUST APPLY THE BUTTON ONCLICK SYNTAX TO THE SAVE BUTTONS]-->
<form name="frmRealForm" method="POST">
     <input type="hidden" name="iSaveAll" value="1">
     <textarea name="txtTextField" value="<%=txtTextField%>"></textarea>
      <input type="checkbox" value="1" name="checkbox" <% if checkbox = true then %>checked<% end if %>>
      <input type="checkbox" value="1" name="checkbox2" <% if checkbox2 = true then %>checked<% end if %>>
   
  <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName','txtTextField',1)">
       <br>
  <textarea  name="txtTextField2" value="<%=txtTextField2%>"></textarea>
<input type="checkbox" value="1" name="checkbox3" <% if checkbox3 = true then %>checked<% end if %>>
<input type="checkbox" value="1" name="checkbox4" <% if checkbox4 = true then %>checked<% end if %>>
 <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName2','txtTextField2',1)">

  <br> <input type="submit" value="SAVE ALL">
</form>
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12648989
Darn...use this one:

<!--;window.location = 'form1.asp?M_USERNAME=<% response.write (session("user"))%>'; -->
<script language="javascript">
function fSaveSingle(strDBField,strFormValue,iIsString){
     iSubmit = 1;
     if (iSubmit == 1){
          if (document.forms.frmRealForm[strFormValue].value == ""){
               alert("This field cannot be empty.");
               iSubmit = 0;
          }
     }
      if (iSubmit == 1){
          document.forms.frmSaveSingle.strDBField.value = strDBField;
          document.forms.frmSaveSingle.strFormValue.value = document.forms.frmRealForm[strFormValue].value;
          document.forms.frmSaveSingle.iIsString.value = iIsString;
            //below code is added
            document.forms.frmSaveSingle.checkbox.value = 0;
            document.forms.frmSaveSingle.checkbox2.value = 0;
            document.forms.frmSaveSingle.checkbox3.value = 0;
            document.forms.frmSaveSingle.checkbox4.value = 0;
            if (document.forms.frmRealForm.checkbox.checked == true){
                  document.forms.frmSaveSingle.checkbox.value = 1;
            }
            if (document.forms.frmRealForm.checkbox2.checked == true){
                  document.forms.frmSaveSingle.checkbox2.value = 1;
            }            
            if (document.forms.frmRealForm.checkbox3.checked == true){
                  document.forms.frmSaveSingle.checkbox3.value = 1;
            }            
            if (document.forms.frmRealForm.checkbox4.checked == true){
                  document.forms.frmSaveSingle.checkbox4.value = 1;
            }            
        document.forms.frmSaveSingle.submit();
     }
}
</script>
<%
'Declare connection object
 Dim straccessdb, conn, strcon
 strAccessDB = "db1.mdb"
 Set Conn = Server.CreateObject("ADODB.Connection")
 strCon = "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=; DBQ=" & Server.MapPath(strAccessDB)
 conn.Open strCon
 'Set rs = Server.createobject("ADODB.recordset")
'Set current user
dim M_USERNAME
M_USERNAME = session("user")

'Set checkbox values
checkbox = False
checkbox2 = False
checkbox3 = False
checkbox4 = False
if cint(request.form("checkbox")) = 1 then
      checkbox = True
end if

if cint(request.form("checkbox2")) = 1 then
      checkbox2 = True
end if

if cint(request.form("checkbox3")) = 1 then
      checkbox3 = True
end if

if cint(request.form("checkbox4")) = 1 then
      checkbox4 = True
end if

Response.write("checkbox1 = " & checkbox & "<br>checkbox2=" & checkbox2)
Response.write("checkbox3 = " & checkbox3 & "<br>checkbox4=" & checkbox4)
       
if request.form("iSaveSingle") = 1 then
      'Saving a single "row"
     strFieldName = request.form("strDBField")
     strFieldValue = request.form("strFormValue")
     iIsString = request.form("iIsString")
'Response.End()
       strQuote = ""
     if iIsString = 1 then
          strQuote = "'"
     end if
     strSQL = "UPDATE check "
     strSQL = strSQL & "SET " & strFieldName & " = " & strQuote & strFieldValue & strQuote & " "
'add check boxes
     strSQL = strSQL & ", checkboxfield = " & checkbox & " "
     strSQL = strSQL & ", checkboxfield2 = " & checkbox2 & " "
     strSQL = strSQL & ", checkboxfield3 = " & checkbox3 & " "
     strSQL = strSQL & ", checkboxfield4 = " & checkbox4 & " "
     strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
     '  response.write strsql
'response.end
      conn.execute(strSQL)
     'response.write("<!-- [JAVASCRIPT POPUP WINDOW CODE HERE FOR PDF FILE] -->");
end if

if request.form("iSaveAll") = "1" then
      'Saving entire form
      strSQL = "UPDATE check SET "
      strSQL = strSQL & "dbTextFieldName = '" & request.form("txtTextField") & "'"
      strSQL = strSQL & "dbTextFieldName2 = '" & request.form("txtTextField2") & "'"
      'add check boxes
      strSQL = strSQL & ", checkboxfield = " & checkbox & " "
      strSQL = strSQL & ", checkboxfield2 = " & checkbox2 & " "
      strSQL = strSQL & ", checkboxfield3 = " & checkbox3 & " "
      strSQL = strSQL & ", checkboxfield4 = " & checkbox4 & " "
      strSQL = strSQL & " WHERE M_USERNAME = '" & session("user") & "'"
      conn.execute(strSQL)
End If


'read from db
strSQL ="SELECT * FROM check  WHERE M_USERNAME = '" & Session("user") & "'"
Set oRS = conn.Execute(strSQL)
checkbox = False
checkbox2 = False
checkbox3 = False
checkbox4 = False
while not oRS.Eof Then
      'get the data
      txtTextField = iRS("txtTextField")
      txtTextField2 = iRS("txtTextField2")
      If  oRS("checkbox") Then
            checkbox=true
      end if
      If  oRS("checkbox2") Then
            checkbox2=true
      end if
      If  oRS("checkbox3") Then
            checkbox3="checked"
      end if
      If  oRS("checkbox4") Then
            checkbox4="checked"
      end if
      oRS.MoveNext
wend
oRS.close
set oRS = nothing
%>
<!-- Hidden Form Here -->
<form method="POST" name="frmSaveSingle">
     <input type="hidden" name="iSaveSingle" value="1">
     <input type="hidden" name="strDBField" value="">
     <input type="hidden" name="strFormValue" value="">
     <input type="hidden" name="iIsString" value="0">    
    <input type="hidden" name="checkbox" value="">
    <input type="hidden" name="checkbox2" value="">
    <input type="hidden" name="checkbox3" value="">
    <input type="hidden" name="checkbox4" value="">

</form>


<!-- Real Form Here  [REPLACE BELOW WITH YOUR EXISTING FORM, JUST APPLY THE BUTTON ONCLICK SYNTAX TO THE SAVE BUTTONS]-->
<form name="frmRealForm" method="POST">
     <input type="hidden" name="iSaveAll" value="1">
     <textarea name="txtTextField" value="<%=txtTextField%>"></textarea>
      <input type="checkbox" value="1" name="checkbox" <% if checkbox = true then %>checked<% end if %>>
      <input type="checkbox" value="1" name="checkbox2" <% if checkbox2 = true then %>checked<% end if %>>
   
  <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName','txtTextField',1)">
       <br>
  <textarea  name="txtTextField2" value="<%=txtTextField2%>"></textarea>
<input type="checkbox" value="1" name="checkbox3" <% if checkbox3 = true then %>checked<% end if %>>
<input type="checkbox" value="1" name="checkbox4" <% if checkbox4 = true then %>checked<% end if %>>
 <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName2','txtTextField2',1)">

  <br> <input type="submit" value="SAVE ALL">
</form>
0
 

Author Comment

by:Melfeky
ID: 12648996
got this:
Error Type:
Microsoft VBScript compilation (0x800A0400)
Expected statement
/pdf1/formtest.asp, line 118, column 18
while not oRS.Eof Then
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12649021
sorry, remove the Then, so change it to:

while not oRS.Eof
0
 

Author Comment

by:Melfeky
ID: 12649071
well there are no errors , but no dta saved in the db and so no data is displayed in the fields too.
I will try to mail u the db again.
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12649101
What are the errors?
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12649104
oh, nevermind
0
 

Author Comment

by:Melfeky
ID: 12649113
there re no errors but when i add data to the field and click the save button and go check the db i don't see any values entered into the db.
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12649137
ok, do you get the same results whether you save a single and save all? Also, do the current user in your session variable exist in your DB?
0
 

Author Comment

by:Melfeky
ID: 12649139
i have sent u an email with the db attached at agent.smith.78@gmail.com
0
 

Author Comment

by:Melfeky
ID: 12649170
when i  click the save button nothing is saved in the db though the page is reloaded .
when i click the save all i get this error:
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression ''s'dbTextFieldName2 = 'a''.
/pdf1/formtest.asp, line 107


0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12649242
OK, replace all with this and test both again:

<!--;window.location = 'form1.asp?M_USERNAME=<% response.write (session("user"))%>'; -->
<script language="javascript">
function fSaveSingle(strDBField,strFormValue,iIsString){
     iSubmit = 1;
     if (iSubmit == 1){
          if (document.forms.frmRealForm[strFormValue].value == ""){
               alert("This field cannot be empty.");
               iSubmit = 0;
          }
     }
      if (iSubmit == 1){
          document.forms.frmSaveSingle.strDBField.value = strDBField;
          document.forms.frmSaveSingle.strFormValue.value = document.forms.frmRealForm[strFormValue].value;
          document.forms.frmSaveSingle.iIsString.value = iIsString;
            //below code is added
            document.forms.frmSaveSingle.checkbox.value = 0;
            document.forms.frmSaveSingle.checkbox2.value = 0;
            document.forms.frmSaveSingle.checkbox3.value = 0;
            document.forms.frmSaveSingle.checkbox4.value = 0;
            if (document.forms.frmRealForm.checkbox.checked == true){
                  document.forms.frmSaveSingle.checkbox.value = 1;
            }
            if (document.forms.frmRealForm.checkbox2.checked == true){
                  document.forms.frmSaveSingle.checkbox2.value = 1;
            }            
            if (document.forms.frmRealForm.checkbox3.checked == true){
                  document.forms.frmSaveSingle.checkbox3.value = 1;
            }            
            if (document.forms.frmRealForm.checkbox4.checked == true){
                  document.forms.frmSaveSingle.checkbox4.value = 1;
            }            
        document.forms.frmSaveSingle.submit();
     }
}
</script>
<%
'Declare connection object
 Dim straccessdb, conn, strcon
 strAccessDB = "db1.mdb"
 Set Conn = Server.CreateObject("ADODB.Connection")
 strCon = "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=; DBQ=" & Server.MapPath(strAccessDB)
 conn.Open strCon

'Set current user
dim M_USERNAME
M_USERNAME = session("user")

'Set checkbox values
checkbox = False
checkbox2 = False
checkbox3 = False
checkbox4 = False
if cint(request.form("checkbox")) = 1 then
      checkbox = True
end if

if cint(request.form("checkbox2")) = 1 then
      checkbox2 = True
end if

if cint(request.form("checkbox3")) = 1 then
      checkbox3 = True
end if

if cint(request.form("checkbox4")) = 1 then
      checkbox4 = True
end if

Response.write("checkbox1 = " & checkbox & "<br>checkbox2=" & checkbox2)
Response.write("checkbox3 = " & checkbox3 & "<br>checkbox4=" & checkbox4)
       
if request.form("iSaveSingle") = 1 then
      'Saving a single "row"
     strFieldName = request.form("strDBField")
     strFieldValue = request.form("strFormValue")
     iIsString = request.form("iIsString")
       strQuote = ""
     if iIsString = 1 then
          strQuote = "'"
     end if
     strSQL = "UPDATE check "
     strSQL = strSQL & "SET " & strFieldName & " = " & strQuote & strFieldValue & strQuote & " "
     strSQL = strSQL & ", checkboxfield = " & checkbox & " "
     strSQL = strSQL & ", checkboxfield2 = " & checkbox2 & " "
     strSQL = strSQL & ", checkboxfield3 = " & checkbox3 & " "
     strSQL = strSQL & ", checkboxfield4 = " & checkbox4 & " "
     strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
      conn.execute(strSQL)
     'response.write("<!-- [JAVASCRIPT POPUP WINDOW CODE HERE FOR PDF FILE] -->");
end if

if request.form("iSaveAll") = "1" then
      'Saving entire form
      strSQL = "UPDATE check SET "
      strSQL = strSQL & "dbTextFieldName = '" & request.form("txtTextField") & "'"
      strSQL = strSQL & ",dbTextFieldName2 = '" & request.form("txtTextField2") & "'"
      'add check boxes
      strSQL = strSQL & ", checkboxfield = " & checkbox & " "
      strSQL = strSQL & ", checkboxfield2 = " & checkbox2 & " "
      strSQL = strSQL & ", checkboxfield3 = " & checkbox3 & " "
      strSQL = strSQL & ", checkboxfield4 = " & checkbox4 & " "
      strSQL = strSQL & " WHERE M_USERNAME = '" & session("user") & "'"
      conn.execute(strSQL)
End If


'read from db
strSQL ="SELECT * FROM check  WHERE M_USERNAME = '" & Session("user") & "'"
Set oRS = conn.Execute(strSQL)
while not oRS.Eof
      'get the data
      txtTextField = iRS("txtTextField")
      txtTextField2 = iRS("txtTextField2")
      If  oRS("checkbox") Then
            checkbox=true
      end if
      If  oRS("checkbox2") Then
            checkbox2=true
      end if
      If  oRS("checkbox3") Then
            checkbox3="checked"
      end if
      If  oRS("checkbox4") Then
            checkbox4="checked"
      end if
      oRS.MoveNext
wend
oRS.close
set oRS = nothing
%>
<!-- Hidden Form Here -->
<form method="POST" name="frmSaveSingle">
     <input type="hidden" name="iSaveSingle" value="1">
     <input type="hidden" name="strDBField" value="">
     <input type="hidden" name="strFormValue" value="">
     <input type="hidden" name="iIsString" value="0">    
    <input type="hidden" name="checkbox" value="">
    <input type="hidden" name="checkbox2" value="">
    <input type="hidden" name="checkbox3" value="">
    <input type="hidden" name="checkbox4" value="">

</form>


<!-- Real Form Here  [REPLACE BELOW WITH YOUR EXISTING FORM, JUST APPLY THE BUTTON ONCLICK SYNTAX TO THE SAVE BUTTONS]-->
<form name="frmRealForm" method="POST">
     <input type="hidden" name="iSaveAll" value="1">
     <textarea name="txtTextField" value="<%=txtTextField%>"></textarea>
      <input type="checkbox" value="1" name="checkbox" <% if checkbox = true then %>checked<% end if %>>
      <input type="checkbox" value="1" name="checkbox2" <% if checkbox2 = true then %>checked<% end if %>>
   
  <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName','txtTextField',1)">
       <br>
  <textarea  name="txtTextField2" value="<%=txtTextField2%>"></textarea>
<input type="checkbox" value="1" name="checkbox3" <% if checkbox3 = true then %>checked<% end if %>>
<input type="checkbox" value="1" name="checkbox4" <% if checkbox4 = true then %>checked<% end if %>>
 <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName2','txtTextField2',1)">

  <br> <input type="submit" value="SAVE ALL">
</form>
0
 

Author Comment

by:Melfeky
ID: 12649243
again i couldn't send you the db.
did u check my last error?
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12649266
yes, try this and let me know if either save single or save all work.
0
 

Author Comment

by:Melfeky
ID: 12649299
again got this error when i click the save all and save buttons:
Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'iRS'
/pdf1/formtest.asp, line 112
0
 

Author Comment

by:Melfeky
ID: 12649315
i have changed irs to oRS, and now i am getting this:
Error Type:
ADODB.Recordset (0x800A0CC1)
Item cannot be found in the collection corresponding to the requested name or ordinal.
/pdf1/formtest.asp, line 114

i guess this is because wrong db field name i will check this and let you know
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12649332
change to this:

<!--;window.location = 'form1.asp?M_USERNAME=<% response.write (session("user"))%>'; -->
<script language="javascript">
function fSaveSingle(strDBField,strFormValue,iIsString){
     iSubmit = 1;
     if (iSubmit == 1){
          if (document.forms.frmRealForm[strFormValue].value == ""){
               alert("This field cannot be empty.");
               iSubmit = 0;
          }
     }
      if (iSubmit == 1){
          document.forms.frmSaveSingle.strDBField.value = strDBField;
          document.forms.frmSaveSingle.strFormValue.value = document.forms.frmRealForm[strFormValue].value;
          document.forms.frmSaveSingle.iIsString.value = iIsString;
            //below code is added
            document.forms.frmSaveSingle.checkbox.value = 0;
            document.forms.frmSaveSingle.checkbox2.value = 0;
            document.forms.frmSaveSingle.checkbox3.value = 0;
            document.forms.frmSaveSingle.checkbox4.value = 0;
            if (document.forms.frmRealForm.checkbox.checked){
                  document.forms.frmSaveSingle.checkbox.value = 1;
            }
            if (document.forms.frmRealForm.checkbox2.checked){
                  document.forms.frmSaveSingle.checkbox2.value = 1;
            }            
            if (document.forms.frmRealForm.checkbox3.checked){
                  document.forms.frmSaveSingle.checkbox3.value = 1;
            }            
            if (document.forms.frmRealForm.checkbox4.checked){
                  document.forms.frmSaveSingle.checkbox4.value = 1;
            }            
        document.forms.frmSaveSingle.submit();
     }
}
</script>
<%
'Declare connection object
 Dim straccessdb, conn, strcon
 strAccessDB = "db1.mdb"
 Set Conn = Server.CreateObject("ADODB.Connection")
 strCon = "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=; DBQ=" & Server.MapPath(strAccessDB)
 conn.Open strCon

'Set current user
dim M_USERNAME
M_USERNAME = session("user")

'Set checkbox values
checkbox = False
checkbox2 = False
checkbox3 = False
checkbox4 = False
if cint(request.form("checkbox")) = 1 then
      checkbox = True
end if

if cint(request.form("checkbox2")) = 1 then
      checkbox2 = True
end if

if cint(request.form("checkbox3")) = 1 then
      checkbox3 = True
end if

if cint(request.form("checkbox4")) = 1 then
      checkbox4 = True
end if

'Response.write("checkbox1 = " & checkbox & "<br>checkbox2=" & checkbox2)
'Response.write("checkbox3 = " & checkbox3 & "<br>checkbox4=" & checkbox4)
       
if request.form("iSaveSingle") = 1 then
      'Saving a single "row"
     strFieldName = request.form("strDBField")
     strFieldValue = request.form("strFormValue")
     iIsString = request.form("iIsString")
       strQuote = ""
     if iIsString = 1 then
          strQuote = "'"
     end if
     strSQL = "UPDATE check "
     strSQL = strSQL & "SET " & strFieldName & " = " & strQuote & strFieldValue & strQuote & " "
     strSQL = strSQL & ", checkboxfield = " & checkbox & " "
     strSQL = strSQL & ", checkboxfield2 = " & checkbox2 & " "
     strSQL = strSQL & ", checkboxfield3 = " & checkbox3 & " "
     strSQL = strSQL & ", checkboxfield4 = " & checkbox4 & " "
     strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
     conn.execute(strSQL)
     'response.write("<!-- [JAVASCRIPT POPUP WINDOW CODE HERE FOR PDF FILE] -->");
end if

if request.form("iSaveAll") = "1" then
      'Saving entire form
      strSQL = "UPDATE check SET "
      strSQL = strSQL & "dbTextFieldName = '" & request.form("txtTextField") & "'"
      strSQL = strSQL & ",dbTextFieldName2 = '" & request.form("txtTextField2") & "'"
      'add check boxes
      strSQL = strSQL & ", checkboxfield = " & checkbox & " "
      strSQL = strSQL & ", checkboxfield2 = " & checkbox2 & " "
      strSQL = strSQL & ", checkboxfield3 = " & checkbox3 & " "
      strSQL = strSQL & ", checkboxfield4 = " & checkbox4 & " "
      strSQL = strSQL & " WHERE M_USERNAME = '" & session("user") & "'"
      conn.execute(strSQL)
End If


'read from db
strSQL ="SELECT * FROM check  WHERE M_USERNAME = '" & Session("user") & "'"
Set oRS = conn.Execute(strSQL)
while not oRS.Eof
      'get the data
      txtTextField = oRS("txtTextField")
      txtTextField2 = oRS("txtTextField2")
      If  oRS("checkbox") Then
            checkbox=true
      end if
      If  oRS("checkbox2") Then
            checkbox2=true
      end if
      If  oRS("checkbox3") Then
            checkbox3="checked"
      end if
      If  oRS("checkbox4") Then
            checkbox4="checked"
      end if
      oRS.MoveNext
wend
oRS.close
set oRS = nothing
%>
<!-- Hidden Form Here -->
<form method="POST" name="frmSaveSingle">
     <input type="hidden" name="iSaveSingle" value="1">
     <input type="hidden" name="strDBField" value="">
     <input type="hidden" name="strFormValue" value="">
     <input type="hidden" name="iIsString" value="0">    
    <input type="hidden" name="checkbox" value="">
    <input type="hidden" name="checkbox2" value="">
    <input type="hidden" name="checkbox3" value="">
    <input type="hidden" name="checkbox4" value="">

</form>


<!-- Real Form Here  [REPLACE BELOW WITH YOUR EXISTING FORM, JUST APPLY THE BUTTON ONCLICK SYNTAX TO THE SAVE BUTTONS]-->
<form name="frmRealForm" method="POST">
     <input type="hidden" name="iSaveAll" value="1">
     <textarea name="txtTextField" value="<%=txtTextField%>"></textarea>
      <input type="checkbox" value="1" name="checkbox" <% if checkbox = true then %>checked<% end if %>>
      <input type="checkbox" value="1" name="checkbox2" <% if checkbox2 = true then %>checked<% end if %>>
   
  <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName','txtTextField',1)">
       <br>
  <textarea  name="txtTextField2" value="<%=txtTextField2%>"></textarea>
<input type="checkbox" value="1" name="checkbox3" <% if checkbox3 = true then %>checked<% end if %>>
<input type="checkbox" value="1" name="checkbox4" <% if checkbox4 = true then %>checked<% end if %>>
 <input type="button" value="Save" onclick="fSaveSingle('dbTextFieldName2','txtTextField2',1)">

  <br> <input type="submit" value="SAVE ALL">
</form>
0
 

Author Comment

by:Melfeky
ID: 12649378
The good news is that the save all and the save now works fine, as i hve changed all the field name in the db to just this:
checkbox
checkbox2
checkbox3
checkbox4

The bad news is that when i click the first save button which is supposed to save only the first text box and the 2 checkboxs beside it,
also saves the values of the other checkboxs too which is not good.
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12649409
i was afraid of that...let me rewrite it so it saves properly
0
 

Author Comment

by:Melfeky
ID: 12649447
another thing i would like to tell u this form is also intended to display the vlues stored in the db in the form fields.
thanks.
good luck;)
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12649605
ok, i'm working on this, what you'll want to do now in the meantime is rename your checkbox database fields to something that corresponds to the text field it relates to, for example:

checkboxfield          -> cb1txtTextField
checkboxfield2        -> cb2txtTextField
checkboxfield3        -> cb1txtTextField2
checkboxfield4        ->cb2txtTextField2

if you rename your fields to this, what I give you should work right away
0
 

Author Comment

by:Melfeky
ID: 12649708
done,
let me know when u are finished?
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12649724
what is the text field name in the database dbtxtTextField or txtTextField?
0
 

Author Comment

by:Melfeky
ID: 12649770
dbTextFieldName
dbTextFieldName2
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12649820
ok, first off, redesign your database to look like this:

field name              datatype                     format
cb1txtTextField          yes/no                       true/false
cb2txtTextField        yes/no                        true/false
cb1txtTextField2        yes/no                        true/false
cb2txtTextField2        yes/no                        true/false
txtTextField             text
txtTextField2           text

NEXT, Use this code...I don't have a DB to test this on so you might get some errors on the first shot...I'm leaving work now, but will be home in about a half an hour. Let me know how it goes..If possible, post this all to a web server where i can preview the results:

<!--;window.location = 'form1.asp?M_USERNAME=<% response.write (session("user"))%>'; -->
<script language="javascript">
function fSaveSingle(strDBField,strFormValue,iIsString){
     iSubmit = 1;
     if (iSubmit == 1){
          if (document.forms.frmRealForm[strFormValue].value == ""){
               alert("This field cannot be empty.");
               iSubmit = 0;
          }
     }
      if (iSubmit == 1){
          document.forms.frmSaveSingle.strDBField.value = strDBField;
          document.forms.frmSaveSingle.strFormValue.value = document.forms.frmRealForm[strFormValue].value;
          document.forms.frmSaveSingle.iIsString.value = iIsString;
            //below code is added
            document.forms.frmSaveSingle.cb1.value = 0;
            document.forms.frmSaveSingle.cb2.value = 0;
            if (document.forms.frmRealForm["cb1" + strFormValue].checked){
                  document.forms.frmSaveSingle.cb1.value = 1;
            }
            if (document.forms.frmRealForm["cb2" + strFormValue].checked){
                  document.forms.frmSaveSingle.cb2.value = 1;
            }            
        document.forms.frmSaveSingle.submit();
     }
}
</script>
<%
'Declare connection object
 Dim straccessdb, conn, strcon
 strAccessDB = "db1.mdb"
 Set Conn = Server.CreateObject("ADODB.Connection")
 strCon = "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=; DBQ=" & Server.MapPath(strAccessDB)
 conn.Open strCon

'Set current user
dim M_USERNAME
M_USERNAME = session("user")

'Response.write("checkbox1 = " & checkbox & "<br>checkbox2=" & checkbox2)
'Response.write("checkbox3 = " & checkbox3 & "<br>checkbox4=" & checkbox4)
       
if request.form("iSaveSingle") = 1 then

      'Saving a single "row"
     strFieldName = request.form("strDBField")
     strFieldValue = request.form("strFormValue")
     iIsString = request.form("iIsString")
       strQuote = ""
     if iIsString = 1 then
          strQuote = "'"
      end if
      cb1 = false
      cb2 = false
      if cint(request.form("cb1")) = 1 then
            cb1 = true
      end if
      if cint(request.form("cb2")) = 1 then
            cb2 = true
      end if
      
     strSQL = "UPDATE check "
     strSQL = strSQL & "SET " & strFieldName & " = " & strQuote & strFieldValue & strQuote & " "
     strSQL = strSQL & ", cb1" & strFieldName & " = " & cb1 & " "
     strSQL = strSQL & ", cb2" & strFieldName & " = " & cb2 & " "
     strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
     conn.execute(strSQL)
     'response.write("<!-- [JAVASCRIPT POPUP WINDOW CODE HERE FOR PDF FILE] -->");
end if

if request.form("iSaveAll") = "1" then
'Set checkbox values
cb1txtTextField = False
cb2txtTextField = False
cb1txtTextField2 = False
cb2txtTextField2 = False
if cint(request.form("cb1txtTextField")) = 1 then
      cb1txtTextField = True
end if

if cint(request.form("cb2txtTextField")) = 1 then
      cb2txtTextField = True
end if

if cint(request.form("cb1txtTextField2")) = 1 then
      cb1txtTextField2 = True
end if

if cint(request.form("cb2txtTextField2")) = 1 then
      cb2txtTextField2 = True
end if
      'Saving entire form
      strSQL = "UPDATE check SET "
      strSQL = strSQL & "txtTextField = '" & request.form("txtTextField") & "'"
      strSQL = strSQL & ",txtTextField2 = '" & request.form("txtTextField2") & "'"
      'add check boxes
      strSQL = strSQL & ", cb1txtTextField = " & cb1txtTextField & " "
      strSQL = strSQL & ", cb2txtTextField = " & cb2txtTextField & " "
      strSQL = strSQL & ", cb1txtTextField2 = " & cb1txtTextField2 & " "
      strSQL = strSQL & ", cb2txtTextField2 = " & cb2txtTextField2 & " "
      strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
      conn.execute(strSQL)
End If


read from db
strSQL ="SELECT * FROM check  WHERE M_USERNAME = '" & Session("user") & "'"
Set oRS = conn.Execute(strSQL)
while not oRS.Eof
      'get the data
      txtTextField = oRS("txtTextField")
      txtTextField2 = oRS("txtTextField2")
      If  oRS("cb1txtTextField") Then
            cb1txtTextField=true
      end if
      If  oRS("cb2txtTextField") Then
            cb2txtTextField=true
      end if
      If  oRS("cb1txtTextField2") Then
            cb1txtTextField2=true
      end if
      If  oRS("cb2txtTextField2") Then
            cb2txtTextField2=true
      end if
      oRS.MoveNext
wend
oRS.close
set oRS = nothing
%>
<!-- Hidden Form Here -->
<%= strSQL %>
<form method="POST" name="frmSaveSingle">
     <input type="hidden" name="iSaveSingle" value="1">
     <input type="hidden" name="strDBField" value="">
     <input type="hidden" name="strFormValue" value="">
     <input type="hidden" name="iIsString" value="0">    
    <input type="hidden" name="cb1" value="">
    <input type="hidden" name="cb2" value="">
</form>


<!-- Real Form Here  [REPLACE BELOW WITH YOUR EXISTING FORM, JUST APPLY THE BUTTON ONCLICK SYNTAX TO THE SAVE BUTTONS]-->
<form name="frmRealForm" method="POST">
     <input type="hidden" name="iSaveAll" value="1">
     <textarea name="txtTextField" value="<%=txtTextField%>"></textarea>
      <input type="checkbox" value="1" name="cb1txtTextField" <% if cb1txtTextField = true then %>checked<% end if %>>
      <input type="checkbox" value="1" name="cb2txtTextField" <% if cb2txtTextField = true then %>checked<% end if %>>
   
  <input type="button" value="Save" onclick="fSaveSingle('txtTextField','txtTextField',1)">
       <br>
  <textarea  name="txtTextField2" value="<%=txtTextField2%>"></textarea>
<input type="checkbox" value="1" name="cb1txtTextField2" <% if cb1txtTextField2 = true then %>checked<% end if %>>
<input type="checkbox" value="1" name="cb2txtTextField2" <% if cb2txtTextField2 = true then %>checked<% end if %>>
 <input type="button" value="Save" onclick="fSaveSingle('txtTextField2','txtTextField2',1)">

  <br> <input type="submit" value="SAVE ALL">
</form>

0
 

Author Comment

by:Melfeky
ID: 12649923
I will upload everything to www.1asphost.com
i will mail u the username and password
0
 

Author Comment

by:Melfeky
ID: 12650056
i got this error:
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.
/pdf1/formtest.asp, line 67
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12650113
what is on line 67?
please post the line code when posting an error like this in the future as my line #'s don't quite mesh exactly with yours.
0
 

Author Comment

by:Melfeky
ID: 12650167
Everything is fine except the text areas dosn't display the stored values from the db.
but the check boxs display the values stored in the db.

i have uploaded everything into my account at www.1asphost.com, i have sent u an email with my user account, u might download the db there too.
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12650177
Is the text field getting inserted into the DB?
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12650232
Melfeky,

what is the URL where I can test this?
0
 

Author Comment

by:Melfeky
ID: 12650266
yes the textfield values are saved into the db.
You can test it here:
http://ccc.1asphost.com/kotty1234/Test/login.asp
login with :
username=dodo
password=dodo
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12650296
Whew...a lot easier that way...Everything seems to be working...here is the final code, though I've already uploaded it for you:

<!--;window.location = 'form1.asp?M_USERNAME=<% response.write (session("user"))%>'; -->
<script language="javascript">
function fSaveSingle(strDBField,strFormValue,iIsString){
     iSubmit = 1;
     if (iSubmit == 1){
          if (document.forms.frmRealForm[strFormValue].value == ""){
               alert("This field cannot be empty.");
               iSubmit = 0;
          }
     }
      if (iSubmit == 1){
          document.forms.frmSaveSingle.strDBField.value = strDBField;
          document.forms.frmSaveSingle.strFormValue.value = document.forms.frmRealForm[strFormValue].value;
          document.forms.frmSaveSingle.iIsString.value = iIsString;
            //below code is added
          document.forms.frmSaveSingle.cb1.value = 0;
          document.forms.frmSaveSingle.cb2.value = 0;
          if (document.forms.frmRealForm["cb1" + strFormValue].checked){
               document.forms.frmSaveSingle.cb1.value = 1;
          }
          if (document.forms.frmRealForm["cb2" + strFormValue].checked){
               document.forms.frmSaveSingle.cb2.value = 1;
          }          
        document.forms.frmSaveSingle.submit();
     }
}
</script>
<%
'Declare connection object
 Dim straccessdb, conn, strcon
 strAccessDB = "db1.mdb"
 Set Conn = Server.CreateObject("ADODB.Connection")
 strCon = "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=; DBQ=" & Server.MapPath(strAccessDB)
 conn.Open strCon

'Set current user
dim M_USERNAME
M_USERNAME = session("user")

'Response.write("checkbox1 = " & checkbox & "<br>checkbox2=" & checkbox2)
'Response.write("checkbox3 = " & checkbox3 & "<br>checkbox4=" & checkbox4)
       
if request.form("iSaveSingle") = 1 then

     'Saving a single "row"
     strFieldName = request.form("strDBField")
     strFieldValue = request.form("strFormValue")
     iIsString = request.form("iIsString")
      strQuote = ""
     if iIsString = 1 then
          strQuote = "'"
     end if
     cb1 = false
     cb2 = false
     if cint(request.form("cb1")) = 1 then
          cb1 = true
     end if
     if cint(request.form("cb2")) = 1 then
          cb2 = true
     end if
     
     strSQL = "UPDATE check "
     strSQL = strSQL & "SET " & strFieldName & " = " & strQuote & strFieldValue & strQuote & " "
     strSQL = strSQL & ", cb1" & strFieldName & " = " & cb1 & " "
     strSQL = strSQL & ", cb2" & strFieldName & " = " & cb2 & " "
     strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
     conn.execute(strSQL)
     'response.write("<!-- [JAVASCRIPT POPUP WINDOW CODE HERE FOR PDF FILE] -->");
end if

if request.form("iSaveAll") = "1" then
'Set checkbox values
cb1txtTextField = False
cb2txtTextField = False
cb1txtTextField2 = False
cb2txtTextField2 = False
if cint(request.form("cb1txtTextField")) = 1 then
     cb1txtTextField = True
end if

if cint(request.form("cb2txtTextField")) = 1 then
     cb2txtTextField = True
end if

if cint(request.form("cb1txtTextField2")) = 1 then
     cb1txtTextField2 = True
end if

if cint(request.form("cb2txtTextField2")) = 1 then
     cb2txtTextField2 = True
end if
     'Saving entire form
     strSQL = "UPDATE check SET "
     strSQL = strSQL & "txtTextField = '" & request.form("txtTextField") & "'"
     strSQL = strSQL & ",txtTextField2 = '" & request.form("txtTextField2") & "'"
     'add check boxes
     strSQL = strSQL & ", cb1txtTextField = " & cb1txtTextField & " "
     strSQL = strSQL & ", cb2txtTextField = " & cb2txtTextField & " "
     strSQL = strSQL & ", cb1txtTextField2 = " & cb1txtTextField2 & " "
     strSQL = strSQL & ", cb2txtTextField2 = " & cb2txtTextField2 & " "
     strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
     conn.execute(strSQL)
End If


'read from db
strSQL ="SELECT * FROM check  WHERE M_USERNAME = '" & Session("user") & "'"
Set oRS = conn.Execute(strSQL)
while not oRS.Eof
     'get the data
     txtTextField = oRS("txtTextField")
     txtTextField2 = oRS("txtTextField2")
     If  oRS("cb1txtTextField") Then
          cb1txtTextField=true
     end if
     If  oRS("cb2txtTextField") Then
          cb2txtTextField=true
     end if
     If  oRS("cb1txtTextField2") Then
          cb1txtTextField2=true
     end if
     If  oRS("cb2txtTextField2") Then
          cb2txtTextField2=true
     end if
     oRS.MoveNext
wend
oRS.close
set oRS = nothing
%>
<!-- Hidden Form Here -->
<%= strSQL %>
<form method="POST" name="frmSaveSingle">
     <input type="hidden" name="iSaveSingle" value="1">
     <input type="hidden" name="strDBField" value="">
     <input type="hidden" name="strFormValue" value="">
     <input type="hidden" name="iIsString" value="0">    
    <input type="hidden" name="cb1" value="">
    <input type="hidden" name="cb2" value="">
</form>


<!-- Real Form Here  [REPLACE BELOW WITH YOUR EXISTING FORM, JUST APPLY THE BUTTON ONCLICK SYNTAX TO THE SAVE BUTTONS]-->
<form name="frmRealForm" method="POST">
     <input type="hidden" name="iSaveAll" value="1">
     <textarea name="txtTextField"><%=txtTextField %></textarea>
     <input type="checkbox" value="1" name="cb1txtTextField" <% if cb1txtTextField = true then %>checked<% end if %>>
     <input type="checkbox" value="1" name="cb2txtTextField" <% if cb2txtTextField = true then %>checked<% end if %>>
   
  <input type="button" value="Save" onclick="fSaveSingle('txtTextField','txtTextField',1)">
       <br>
  <textarea  name="txtTextField2"><%=txtTextField2 %></textarea>
<input type="checkbox" value="1" name="cb1txtTextField2" <% if cb1txtTextField2 = true then %>checked<% end if %>>
<input type="checkbox" value="1" name="cb2txtTextField2" <% if cb2txtTextField2 = true then %>checked<% end if %>>
 <input type="button" value="Save" onclick="fSaveSingle('txtTextField2','txtTextField2',1)">

  <br> <input type="submit" value="SAVE ALL">
</form>
0
 

Author Comment

by:Melfeky
ID: 12650442
Good job,
thanks for your help.

I have a small question:
can i change those fields names in the db?
i mean can i change them to something else ? as i have a pdf form that will take its values from that table, and it have to be with the same field names?
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12650517
yes, you could, but you'd have to change their names in the file as well. also, you'd need to make sure that for the checkboxes cb1 & cb2 preceeded the exact name you give it in the DB, in the code as well as in the DB...I can do the change for you, but might not be able to get to it until tomorrow morning...Also, one thing I'd like to add is a function that will make your text fields "query-friendly" this means that inserting special symbols like apostophe, etc will not generate errors.
0
 

Author Comment

by:Melfeky
ID: 12650586
well that will be great,
I will try to make the form today with all the fields and set the field names in the db.
so when u come here tomorrow u will see everything at 1asphost.com
but i don'nt wnt the names of the fields in the db to be preceeded with cp,if this cann't be done i cn send you the form that populate the data from the db into the pdf and u tell me where exactly i shall update the change in the db field names.
Let me know what do u think.
Thanks
0
 

Author Comment

by:Melfeky
ID: 12651200
Hello Agent Smith,
i have succesfully added a new text are and 2 checkboxs using the same
field name but only changing the lst number at the end of it to be:
cb1txtTextField3
cb2txtTextField3
txtTextField3

and everything worked fine, but this field names won't work for me as i have lots of fields that need to have relevant names.
So  i have tried to do is to add fields with preceeding cb1, cb2 , and txtTextField
so i have added those fields into the form:
cb1_11a
cb2_11b
txtTextField_Name1

as the actual field names in the pdf is 11a,11b,Name1.
So the saveall button works fine but when i click the save button it is not saved and again get the error in the status bar.

I guess there is something wrong with the savesingle function.

0
 

Author Comment

by:Melfeky
ID: 12651207
Another thing that i would like to know,
can we also make the "SaveAll" function acts like the "SaveSingle" function in a way that we only refer to fields by cb1, and cb2?
if u cann't ,its not a problem.I am asking for this because  the functions that u have built saves  lot of time.

I am going to upload the form with the added fields so u can debug them , along with the db .

I will have go to sleep now, when u login tomorrow ,please check the files so when i come back i can go on with my work.

Thanks again
Melfeky
0
 
LVL 13

Expert Comment

by:nurbek
ID: 12653738
Melfeky,
for what you are using "SaveAll" and "SaveSingle"?
what is the differences between the forms?
0
 

Author Comment

by:Melfeky
ID: 12654325
Hello nurbek,
"SaveAll" and "SaveSingle" they are buttons in the form , where saveall is used to save all the fields that are in the form while savesingle is used to save the fields that are on the same line as the save button (only one text area,2 checkboxs)
0
 
LVL 13

Expert Comment

by:nurbek
ID: 12654419
I understand that

but why there is savesingle?
it saves the field one by one (can able to save all)
what is the purpose of using this?

save all also does the same thing (saves all the fields)




0
 

Author Comment

by:Melfeky
ID: 12654469
the sve single saves the values entered in those fields and opens another pdf form that gets the vlues of its fields from those entered in our form
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12655349
Melfeky,

First of all, it will be possible to make your variable naming convention different from the one I gave you, but to keep this code as simple as possible  your checkbox names should have the field name that they are associated with in them, for example, if the textfield name is "Username" the checkboxes should follow a consistent convention like:

chk1_Username
chk2_Username

I see your form, just let me know what your field names are going to be before I proceed on this.

Secondly, I'm not sure what you mean about making the Save All button only save the checkbox items. Please elaborate. i am agreeing to help you with this, though to be perfectly honest I feel that your question has already been answered and that we're kind of going beyond the scope of this question.
0
 

Author Comment

by:Melfeky
ID: 12655700
I don't want to overload you by doing the field names by yourself i just want u to guide me how to do the field name thing.
so now lets take for exmple this :
i have got 3 text area fields:
Name1
Position_in_Firm
Percentage_of_Ownership_I

the checkboxs field names:

11a
11b
12a
12b
13a
13b

My second question was :"can we also make the "SaveAll" function acts like the "SaveSingle" function in a way that we only refer to fields by cb1, and cb2?

as when viewing your code i saw that in the save single you refered to the fields by using just cb1 and cb2 without refering to each field by its own.
Anyway  neglect that question and lets just focus on changing the field names.

0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12655766
OK, If I adapt this form to work with these field names it's going to make the code a lot more complicated than it needs to be...it wouldn't be possible to name the checkboxes something that has the text field name in it?

like:

Name_cb1
Name_cb2
Position_in_Firm_cb1
Position_in_Firm_cb2
Percentage_of_Ownership_I_cb1
Percentage_of_Ownership_I_cb1

??
0
 

Author Comment

by:Melfeky
ID: 12656022
wow ,this is  lot of complicated code and also so confusing names as the checkboxs name
where like this
11a
11b
12a
12b
13a
13b

which far way than u suggested.

i will have to change all the fields in the pdf form to match the one that u have in our form now.
so forget about changing the field names.
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12656936
ok, assuming your field names match what you mentioned above:

Name1
11a
11b

Position_in_Firm
12a
12b

Percentage_of_Ownership_I
13a
13b

THIS should work:
<!--;window.location = 'form1.asp?M_USERNAME=<% response.write (session("user"))%>'; -->
<script language="javascript">
function fSaveSingle(strDBField,strFormValue,iIsString,chk1Field,chk1Value,chk2Field,chk2Value){
     iSubmit = 1;
     if (iSubmit == 1){
          if (document.forms.frmRealForm[strFormValue].value == ""){
               alert("This field cannot be empty.");
               iSubmit = 0;
          }
     }
      if (iSubmit == 1){
          document.forms.frmSaveSingle.strDBField.value = strDBField;
          document.forms.frmSaveSingle.strFormValue.value = document.forms.frmRealForm[strFormValue].value;
          document.forms.frmSaveSingle.iIsString.value = iIsString;
            //below code is added
                  document.forms.frmSaveSingle.cb1Field.value = chk1Field;
                  document.forms.frmSaveSingle.cb2Field.value = chk2Field;                  
          document.forms.frmSaveSingle.cb1Value.value = 0;
          document.forms.frmSaveSingle.cb2Value.value = 0;
          if (document.forms.frmRealForm[chk1Value].checked){
               document.forms.frmSaveSingle.cb1Value.value = 1;
          }
          if (document.forms.frmRealForm[chk2Value].checked){
               document.forms.frmSaveSingle.cb2Value.value = 1;
          }          
        document.forms.frmSaveSingle.submit();
     }
}
</script>
<%
'Declare connection object
 Dim straccessdb, conn, strcon
 strAccessDB = "db1.mdb"
 Set Conn = Server.CreateObject("ADODB.Connection")
 strCon = "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=; DBQ=" & Server.MapPath(strAccessDB)
 conn.Open strCon

'Set current user
dim M_USERNAME
M_USERNAME = session("user")
       
if request.form("iSaveSingle") = 1 then
     'Saving a single "row"
     strFieldName = request.form("strDBField")
     strFieldValue = request.form("strFormValue")
     iIsString = request.form("iIsString")
      strQuote = ""
     if iIsString = 1 then
          strQuote = "'"
     end if
     cb1 = false
     cb2 = false
     if cint(request.form("cb1Value")) = 1 then
          cb1 = true
     end if
     if cint(request.form("cb2Value")) = 1 then
          cb2 = true
     end if
     
     strSQL = "UPDATE check "
     strSQL = strSQL & "SET " & strFieldName & " = " & strQuote & strFieldValue & strQuote & " "
     strSQL = strSQL & ", " & request.form("cb1Field") & " = " & cb1 & " "
     strSQL = strSQL & ", " & request.form("cb2Field") & " = " & cb2 & " "
     strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
     conn.execute(strSQL)
     'response.write("<!-- [JAVASCRIPT POPUP WINDOW CODE HERE FOR PDF FILE] -->");
end if

if request.form("iSaveAll") = "1" then
'Set checkbox values
cb1 = False
cb2 = False
cb3 = False
cb4 = False
cb5 = False
cb6 = False
if cint(request.form("cb1")) = 1 then
     cb1 = True
end if

if cint(request.form("cb2")) = 1 then
     cb2 = True
end if

if cint(request.form("cb3")) = 1 then
     cb3 = True
end if

if cint(request.form("cb4")) = 1 then
     cb4 = True
end if
  if cint(request.form("cb5")) = 1 then
     cb5 = True
end if

if cint(request.form("cb6")) = 1 then
     cb6 = True
end if
     'Saving entire form
     strSQL = "UPDATE check SET "
     strSQL = strSQL & "txtTextField = '" & request.form("txtTextField") & "'"
     strSQL = strSQL & ",txtTextField2 = '" & request.form("txtTextField2") & "'"
     strSQL = strSQL & ",txtTextField3 = '" & request.form("txtTextField3") & "'"
       strSQL = strSQL & ",txtTextField_Name1 = '" & request.form("txtTextField_Name1") & "'"
       'add check boxes
     strSQL = strSQL & ", 11a = " & cb1 & " "
     strSQL = strSQL & ", 11b = " & cb2 & " "
     strSQL = strSQL & ", 12a = " & cb3 & " "
     strSQL = strSQL & ", 12b = " & cb4 & " "
     strSQL = strSQL & ", 13a = " & cb5 & " "
     strSQL = strSQL & ", 13b = " & cb6 & " "
       strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
     conn.execute(strSQL)
End If


'read from db
strSQL ="SELECT * FROM check  WHERE M_USERNAME = '" & Session("user") & "'"
Set oRS = conn.Execute(strSQL)
while not oRS.Eof
     'get the data
     Name1 = oRS("Name1")
     Position_in_Firm = oRS("Position_in_Firm")
     Percentage_of_Ownership_I = oRS("Percentage_of_Ownership_I")
       If  oRS("11a") Then
          cb1=true
     end if
     If  oRS("11b") Then
          cb2=true
     end if
     If  oRS("12a") Then
          cb3=true
     end if
     If  oRS("12b") Then
          cb4=true
     end if
            If  oRS("13a") Then
          cb5=true
     end if
     If  oRS("13b") Then
          cb6=true
     end if
       oRS.MoveNext
wend
oRS.close
set oRS = nothing
%>
<!-- Hidden Form Here -->
<%= strSQL %>
<form method="POST" name="frmSaveSingle">
     <input type="hidden" name="iSaveSingle" value="1">
     <input type="hidden" name="strDBField" value="">
     <input type="hidden" name="strFormValue" value="">
     <input type="hidden" name="iIsString" value="0">    
    <input type="hidden" name="cb1Field" value="">
    <input type="hidden" name="cb1Value" value="">      
    <input type="hidden" name="cb2Field" value="">
    <input type="hidden" name="cb2Value" value="">      
</form>


<!-- Real Form Here  [REPLACE BELOW WITH YOUR EXISTING FORM, JUST APPLY THE BUTTON ONCLICK SYNTAX TO THE SAVE BUTTONS]-->
<form name="frmRealForm" method="POST">
     <input type="hidden" name="iSaveAll" value="1">
     <textarea name="txtTextField"><%=txtTextField %></textarea>
     <input type="checkbox" value="1" name="cb1" <% if cb1 = true then %>checked<% end if %>>
     <input type="checkbox" value="1" name="cb2" <% if cb2 = true then %>checked<% end if %>>
   
  <input type="button" value="Save" onclick="fSaveSingle('Name1','txtTextField',1,'cb1','11a','cb2','11b')">
       <br>
  <textarea  name="txtTextField2"><%=txtTextField2 %></textarea>
<input type="checkbox" value="1" name="cb3" <% if cb3 = true then %>checked<% end if %>>
<input type="checkbox" value="1" name="cb4" <% if cb4 = true then %>checked<% end if %>>
 <input type="button" value="Save" onclick="fSaveSingle('Position_in_Firm','txtTextField2',1,'cb3','12a','cb4','12b')">
     <br>
       <textarea name="txtTextField3"><%=txtTextField3 %></textarea>
     <input type="checkbox" value="1" name="cb5" <% if cb5 = true then %>checked<% end if %>>
     <input type="checkbox" value="1" name="cb6" <% if cb6 = true then %>checked<% end if %>>
  <input type="button" value="Save" onclick="fSaveSingle('Percentage_of_Ownership_I','txtTextField3',1,'cb5','13a','cb6','13b')">

  <br>
   <input type="submit" value="SAVE ALL">
</form>
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12657060
sry, replace with this:

<!--;window.location = 'form1.asp?M_USERNAME=<% response.write (session("user"))%>'; -->
<script language="javascript">
function fSaveSingle(strDBField,strFormValue,iIsString,chk1Field,chk1Value,chk2Field,chk2Value){
     iSubmit = 1;
     if (iSubmit == 1){
          if (document.forms.frmRealForm[strFormValue].value == ""){
               alert("This field cannot be empty.");
               iSubmit = 0;
          }
     }
      if (iSubmit == 1){
          document.forms.frmSaveSingle.strDBField.value = strDBField;
          document.forms.frmSaveSingle.strFormValue.value = document.forms.frmRealForm[strFormValue].value;
          document.forms.frmSaveSingle.iIsString.value = iIsString;
            //below code is added
                  document.forms.frmSaveSingle.cb1Field.value = chk1Field;
                  document.forms.frmSaveSingle.cb2Field.value = chk2Field;                  
          document.forms.frmSaveSingle.cb1Value.value = 0;
          document.forms.frmSaveSingle.cb2Value.value = 0;
          if (document.forms.frmRealForm[chk1Value].checked){
               document.forms.frmSaveSingle.cb1Value.value = 1;
          }
          if (document.forms.frmRealForm[chk2Value].checked){
               document.forms.frmSaveSingle.cb2Value.value = 1;
          }          
        document.forms.frmSaveSingle.submit();
     }
}
</script>
<%
'Declare connection object
 Dim straccessdb, conn, strcon
 strAccessDB = "db1.mdb"
 Set Conn = Server.CreateObject("ADODB.Connection")
 strCon = "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=; DBQ=" & Server.MapPath(strAccessDB)
 conn.Open strCon

'Set current user
dim M_USERNAME
M_USERNAME = session("user")
       
if request.form("iSaveSingle") = 1 then
     'Saving a single "row"
     strFieldName = request.form("strDBField")
     strFieldValue = request.form("strFormValue")
     iIsString = request.form("iIsString")
      strQuote = ""
     if iIsString = 1 then
          strQuote = "'"
     end if
     cb1 = false
     cb2 = false
     if cint(request.form("cb1Value")) = 1 then
          cb1 = true
     end if
     if cint(request.form("cb2Value")) = 1 then
          cb2 = true
     end if
     
     strSQL = "UPDATE check "
     strSQL = strSQL & "SET " & strFieldName & " = " & strQuote & strFieldValue & strQuote & " "
     strSQL = strSQL & ", " & request.form("cb1Field") & " = " & cb1 & " "
     strSQL = strSQL & ", " & request.form("cb2Field") & " = " & cb2 & " "
     strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
     conn.execute(strSQL)
     'response.write("<!-- [JAVASCRIPT POPUP WINDOW CODE HERE FOR PDF FILE] -->");
end if

if request.form("iSaveAll") = "1" then
'Set checkbox values
cb1 = False
cb2 = False
cb3 = False
cb4 = False
cb5 = False
cb6 = False
if cint(request.form("cb1")) = 1 then
     cb1 = True
end if

if cint(request.form("cb2")) = 1 then
     cb2 = True
end if

if cint(request.form("cb3")) = 1 then
     cb3 = True
end if

if cint(request.form("cb4")) = 1 then
     cb4 = True
end if
  if cint(request.form("cb5")) = 1 then
     cb5 = True
end if

if cint(request.form("cb6")) = 1 then
     cb6 = True
end if
     'Saving entire form
     strSQL = "UPDATE check SET "
     strSQL = strSQL & "txtTextField = '" & request.form("txtTextField") & "'"
     strSQL = strSQL & ",txtTextField2 = '" & request.form("txtTextField2") & "'"
     strSQL = strSQL & ",txtTextField3 = '" & request.form("txtTextField3") & "'"
       strSQL = strSQL & ",txtTextField_Name1 = '" & request.form("txtTextField_Name1") & "'"
       'add check boxes
     strSQL = strSQL & ", 11a = " & cb1 & " "
     strSQL = strSQL & ", 11b = " & cb2 & " "
     strSQL = strSQL & ", 12a = " & cb3 & " "
     strSQL = strSQL & ", 12b = " & cb4 & " "
     strSQL = strSQL & ", 13a = " & cb5 & " "
     strSQL = strSQL & ", 13b = " & cb6 & " "
       strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
     conn.execute(strSQL)
End If


'read from db
strSQL ="SELECT * FROM check  WHERE M_USERNAME = '" & Session("user") & "'"
Set oRS = conn.Execute(strSQL)
while not oRS.Eof
     'get the data
     Name1 = oRS("Name1")
     Position_in_Firm = oRS("Position_in_Firm")
     Percentage_of_Ownership_I = oRS("Percentage_of_Ownership_I")
       If  oRS("11a") Then
          cb1=true
     end if
     If  oRS("11b") Then
          cb2=true
     end if
     If  oRS("12a") Then
          cb3=true
     end if
     If  oRS("12b") Then
          cb4=true
     end if
            If  oRS("13a") Then
          cb5=true
     end if
     If  oRS("13b") Then
          cb6=true
     end if
       oRS.MoveNext
wend
oRS.close
set oRS = nothing
%>
<!-- Hidden Form Here -->
<%= strSQL %>
<form method="POST" name="frmSaveSingle">
     <input type="hidden" name="iSaveSingle" value="1">
     <input type="hidden" name="strDBField" value="">
     <input type="hidden" name="strFormValue" value="">
     <input type="hidden" name="iIsString" value="0">    
    <input type="hidden" name="cb1Field" value="">
    <input type="hidden" name="cb1Value" value="">      
    <input type="hidden" name="cb2Field" value="">
    <input type="hidden" name="cb2Value" value="">      
</form>


<!-- Real Form Here  [REPLACE BELOW WITH YOUR EXISTING FORM, JUST APPLY THE BUTTON ONCLICK SYNTAX TO THE SAVE BUTTONS]-->
<form name="frmRealForm" method="POST">
     <input type="hidden" name="iSaveAll" value="1">
     <textarea name="txtTextField"><%= Name1 %></textarea>
     <input type="checkbox" value="1" name="cb1" <% if cb1 = true then %>checked<% end if %>>
     <input type="checkbox" value="1" name="cb2" <% if cb2 = true then %>checked<% end if %>>
   
  <input type="button" value="Save" onclick="fSaveSingle('Name1','txtTextField',1,'cb1','11a','cb2','11b')">
       <br>
  <textarea  name="txtTextField2"><%= Position_in_Firm %></textarea>
<input type="checkbox" value="1" name="cb3" <% if cb3 = true then %>checked<% end if %>>
<input type="checkbox" value="1" name="cb4" <% if cb4 = true then %>checked<% end if %>>
 <input type="button" value="Save" onclick="fSaveSingle('Position_in_Firm','txtTextField2',1,'cb3','12a','cb4','12b')">
     <br>
       <textarea name="txtTextField3"><%= Percentage_of_Ownership_I %></textarea>
     <input type="checkbox" value="1" name="cb5" <% if cb5 = true then %>checked<% end if %>>
     <input type="checkbox" value="1" name="cb6" <% if cb6 = true then %>checked<% end if %>>
  <input type="button" value="Save" onclick="fSaveSingle('Percentage_of_Ownership_I','txtTextField3',1,'cb5','13a','cb6','13b')">

  <br>
   <input type="submit" value="SAVE ALL">
</form>
0
 

Author Comment

by:Melfeky
ID: 12657513
You don't lose hope,ever ;)
I have pasted the bove code and named the fields in the db the same as u have stated above:
Name1
Position_in_Firm
11a
11b
12a
12b

NO values is saved in the db when clicking the saveall button .
When clicking the save button, i get an error in the status bar and no values is saved into the db too.
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12657547
ok, is the latest posted at your web space? if so, please do so along with the latest database, etc & i will troubleshoot
0
 

Author Comment

by:Melfeky
ID: 12657590
I have uploaded the file and the db so u can test it .
http://ccc.1asphost.com/kotty1234/Test/login.asp

username=dodo
pssword=dodo
0
 

Author Comment

by:Melfeky
ID: 12657848
were u able to open the page?
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12657896
YEP, should be all set..."Final" code is as follows, though I've already uploaded it to your site:

<!--;window.location = 'form1.asp?M_USERNAME=<% response.write (session("user"))%>'; -->
<script language="javascript">
function fSaveSingle(strDBField,strFormValue,iIsString,chk1Field,chk1Value,chk2Field,chk2Value){
     iSubmit = 1;
     if (iSubmit == 1){
          if (document.forms.frmRealForm[strFormValue].value == ""){
               alert("This field cannot be empty.");
               iSubmit = 0;
          }
     }
      if (iSubmit == 1){
          document.forms.frmSaveSingle.strDBField.value = strDBField;
          document.forms.frmSaveSingle.strFormValue.value = document.forms.frmRealForm[strFormValue].value;
          document.forms.frmSaveSingle.iIsString.value = iIsString;
            //below code is added
               document.forms.frmSaveSingle.cb1Field.value = chk1Field;
               document.forms.frmSaveSingle.cb2Field.value = chk2Field;              
          document.forms.frmSaveSingle.cb1Value.value = 0;
          document.forms.frmSaveSingle.cb2Value.value = 0;
          if (document.forms.frmRealForm[chk1Value].checked){
               document.forms.frmSaveSingle.cb1Value.value = 1;
          }
          if (document.forms.frmRealForm[chk2Value].checked){
               document.forms.frmSaveSingle.cb2Value.value = 1;
          }          
        document.forms.frmSaveSingle.submit();
     }
}
</script>
<%
'Declare connection object
 Dim straccessdb, conn, strcon
 strAccessDB = "db1.mdb"
 Set Conn = Server.CreateObject("ADODB.Connection")
 strCon = "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=; DBQ=" & Server.MapPath(strAccessDB)
 conn.Open strCon

'Set current user
dim M_USERNAME
M_USERNAME = session("user")
       
if request.form("iSaveSingle") = 1 then
     'Saving a single "row"
     strFieldName = request.form("strDBField")
     strFieldValue = request.form("strFormValue")
     iIsString = request.form("iIsString")
      strQuote = ""
     if iIsString = 1 then
          strQuote = "'"
     end if
     cb1 = false
     cb2 = false
     if cint(request.form("cb1Value")) = 1 then
          cb1 = true
     end if
     if cint(request.form("cb2Value")) = 1 then
          cb2 = true
     end if
     
     strSQL = "UPDATE check "
     strSQL = strSQL & "SET " & strFieldName & " = " & strQuote & strFieldValue & strQuote & " "
     strSQL = strSQL & ", " & request.form("cb1Field") & " = " & cb1 & " "
     strSQL = strSQL & ", " & request.form("cb2Field") & " = " & cb2 & " "
     strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
     conn.execute(strSQL)
     'response.write("<!-- [JAVASCRIPT POPUP WINDOW CODE HERE FOR PDF FILE] -->");
end if

if request.form("iSaveAll") = "1" then
'Set checkbox values
cb1 = False
cb2 = False
cb3 = False
cb4 = False
cb5 = False
cb6 = False
if cint(request.form("cb1")) = 1 then
     cb1 = True
end if

if cint(request.form("cb2")) = 1 then
     cb2 = True
end if

if cint(request.form("cb3")) = 1 then
     cb3 = True
end if

if cint(request.form("cb4")) = 1 then
     cb4 = True
end if
  if cint(request.form("cb5")) = 1 then
     cb5 = True
end if

if cint(request.form("cb6")) = 1 then
     cb6 = True
end if
     'Saving entire form
     strSQL = "UPDATE check SET "
     strSQL = strSQL & "Name1 = '" & request.form("txtTextField") & "'"
     strSQL = strSQL & ",Position_in_Firm = '" & request.form("txtTextField2") & "'"
     strSQL = strSQL & ",Percentage_of_Ownership_I = '" & request.form("txtTextField3") & "'"
      'add check boxes
     strSQL = strSQL & ", 11a = " & cb1 & " "
     strSQL = strSQL & ", 11b = " & cb2 & " "
     strSQL = strSQL & ", 12a = " & cb3 & " "
     strSQL = strSQL & ", 12b = " & cb4 & " "
     strSQL = strSQL & ", 13a = " & cb5 & " "
     strSQL = strSQL & ", 13b = " & cb6 & " "
      strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
     conn.execute(strSQL)
End If


'read from db
strSQL ="SELECT * FROM check WHERE M_USERNAME = '" & Session("user") & "'"
Set oRS = conn.Execute(strSQL)
while not oRS.Eof
     'get the data
     Name1 = oRS("Name1")
     Position_in_Firm = oRS("Position_in_Firm")
     Percentage_of_Ownership_I = oRS("Percentage_of_Ownership_I")
      If  oRS("11a") Then
          cb1=true
     end if
     If  oRS("11b") Then
          cb2=true
     end if
     If  oRS("12a") Then
          cb3=true
     end if
     If  oRS("12b") Then
          cb4=true
     end if
           If  oRS("13a") Then
          cb5=true
     end if
     If  oRS("13b") Then
          cb6=true
     end if
      oRS.MoveNext
wend
oRS.close
set oRS = nothing
%>
<!-- Hidden Form Here -->
<form method="POST" name="frmSaveSingle">
     <input type="hidden" name="iSaveSingle" value="1">
     <input type="hidden" name="strDBField" value="">
     <input type="hidden" name="strFormValue" value="">
     <input type="hidden" name="iIsString" value="0">    
    <input type="hidden" name="cb1Field" value="">
    <input type="hidden" name="cb1Value" value="">    
    <input type="hidden" name="cb2Field" value="">
    <input type="hidden" name="cb2Value" value="">    
</form>


<!-- Real Form Here  [REPLACE BELOW WITH YOUR EXISTING FORM, JUST APPLY THE BUTTON ONCLICK SYNTAX TO THE SAVE BUTTONS]-->
<form name="frmRealForm" method="POST">
     <input type="hidden" name="iSaveAll" value="1">
     <textarea name="txtTextField"><%= Name1 %></textarea>
     <input type="checkbox" value="1" name="cb1" <% if cb1 = true then %>checked<% end if %>>
     <input type="checkbox" value="1" name="cb2" <% if cb2 = true then %>checked<% end if %>>
   
  <input type="button" value="Save" onclick="fSaveSingle('Name1','txtTextField',1,'11a','cb1','11b','cb2')">
       <br>
  <textarea  name="txtTextField2"><%= Position_in_Firm %></textarea>
<input type="checkbox" value="1" name="cb3" <% if cb3 = true then %>checked<% end if %>>
<input type="checkbox" value="1" name="cb4" <% if cb4 = true then %>checked<% end if %>>
 <input type="button" value="Save" onclick="fSaveSingle('Position_in_Firm','txtTextField2',1,'12a','cb3','12b','cb4')">
     <br>
      <textarea name="txtTextField3"><%= Percentage_of_Ownership_I %></textarea>
     <input type="checkbox" value="1" name="cb5" <% if cb5 = true then %>checked<% end if %>>
     <input type="checkbox" value="1" name="cb6" <% if cb6 = true then %>checked<% end if %>>
  <input type="button" value="Save" onclick="fSaveSingle('Percentage_of_Ownership_I','txtTextField3',1,'13a','cb5','13b','cb6')">

  <br>
   <input type="submit" value="SAVE ALL">
</form>
 
 
 
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12657976
As I said I would, here is the version with a little "Query-friendly" routine that will allow users to enter apostrophe's without it generating errors:

<!--;window.location = 'form1.asp?M_USERNAME=<% response.write (session("user"))%>'; -->
<script language="javascript">
function fSaveSingle(strDBField,strFormValue,iIsString,chk1Field,chk1Value,chk2Field,chk2Value){
     iSubmit = 1;
     if (iSubmit == 1){
          if (document.forms.frmRealForm[strFormValue].value == ""){
               alert("This field cannot be empty.");
               iSubmit = 0;
          }
     }
      if (iSubmit == 1){
          document.forms.frmSaveSingle.strDBField.value = strDBField;
          document.forms.frmSaveSingle.strFormValue.value = document.forms.frmRealForm[strFormValue].value;
          document.forms.frmSaveSingle.iIsString.value = iIsString;
            //below code is added
               document.forms.frmSaveSingle.cb1Field.value = chk1Field;
               document.forms.frmSaveSingle.cb2Field.value = chk2Field;              
          document.forms.frmSaveSingle.cb1Value.value = 0;
          document.forms.frmSaveSingle.cb2Value.value = 0;
          if (document.forms.frmRealForm[chk1Value].checked){
               document.forms.frmSaveSingle.cb1Value.value = 1;
          }
          if (document.forms.frmRealForm[chk2Value].checked){
               document.forms.frmSaveSingle.cb2Value.value = 1;
          }          
        document.forms.frmSaveSingle.submit();
     }
}
</script>
<%
'Declare connection object
 Dim straccessdb, conn, strcon
 strAccessDB = "db1.mdb"
 Set Conn = Server.CreateObject("ADODB.Connection")
 strCon = "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=; DBQ=" & Server.MapPath(strAccessDB)
 conn.Open strCon

'Function to make SQL statements not fail w/ special character(s)
function fQueryFriendly(strVar)
      strTemp = strVar
      strTemp = Replace(strTemp,"","''")
      strTemp = Replace(strTemp,chr(34),"&quot;")
      fQueryFriendly = strTemp
end function

'Set current user
dim M_USERNAME
M_USERNAME = session("user")
       
if request.form("iSaveSingle") = 1 then
     'Saving a single "row"
     strFieldName = request.form("strDBField")
     strFieldValue = request.form("strFormValue")
     iIsString = request.form("iIsString")
      strQuote = ""
     if iIsString = 1 then
          strQuote = "'"
     end if
     cb1 = false
     cb2 = false
     if cint(request.form("cb1Value")) = 1 then
          cb1 = true
     end if
     if cint(request.form("cb2Value")) = 1 then
          cb2 = true
     end if
     
     strSQL = "UPDATE check "
     strSQL = strSQL & "SET " & strFieldName & " = " & strQuote & fQueryFriendly(strFieldValue) & strQuote & " "
     strSQL = strSQL & ", " & request.form("cb1Field") & " = " & cb1 & " "
     strSQL = strSQL & ", " & request.form("cb2Field") & " = " & cb2 & " "
     strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
     conn.execute(strSQL)
     'response.write("<!-- [JAVASCRIPT POPUP WINDOW CODE HERE FOR PDF FILE] -->");
end if

if request.form("iSaveAll") = "1" then
'Set checkbox values
cb1 = False
cb2 = False
cb3 = False
cb4 = False
cb5 = False
cb6 = False
if cint(request.form("cb1")) = 1 then
     cb1 = True
end if

if cint(request.form("cb2")) = 1 then
     cb2 = True
end if

if cint(request.form("cb3")) = 1 then
     cb3 = True
end if

if cint(request.form("cb4")) = 1 then
     cb4 = True
end if
  if cint(request.form("cb5")) = 1 then
     cb5 = True
end if

if cint(request.form("cb6")) = 1 then
     cb6 = True
end if
     'Saving entire form
     strSQL = "UPDATE check SET "
     strSQL = strSQL & "Name1 = '" & fQueryFriendly(request.form("txtTextField")) & "'"
     strSQL = strSQL & ",Position_in_Firm = '" & fQueryFriendly(request.form("txtTextField2")) & "'"
     strSQL = strSQL & ",Percentage_of_Ownership_I = '" & fQueryFriendly(request.form("txtTextField3")) & "'"
      'add check boxes
     strSQL = strSQL & ", 11a = " & cb1 & " "
     strSQL = strSQL & ", 11b = " & cb2 & " "
     strSQL = strSQL & ", 12a = " & cb3 & " "
     strSQL = strSQL & ", 12b = " & cb4 & " "
     strSQL = strSQL & ", 13a = " & cb5 & " "
     strSQL = strSQL & ", 13b = " & cb6 & " "
      strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
     conn.execute(strSQL)
End If


'read from db
strSQL ="SELECT * FROM check WHERE M_USERNAME = '" & Session("user") & "'"
Set oRS = conn.Execute(strSQL)
while not oRS.Eof
     'get the data
     Name1 = oRS("Name1")
     Position_in_Firm = oRS("Position_in_Firm")
     Percentage_of_Ownership_I = oRS("Percentage_of_Ownership_I")
      If  oRS("11a") Then
          cb1=true
     end if
     If  oRS("11b") Then
          cb2=true
     end if
     If  oRS("12a") Then
          cb3=true
     end if
     If  oRS("12b") Then
          cb4=true
     end if
           If  oRS("13a") Then
          cb5=true
     end if
     If  oRS("13b") Then
          cb6=true
     end if
      oRS.MoveNext
wend
oRS.close
set oRS = nothing
%>
<!-- Hidden Form Here -->
<form method="POST" name="frmSaveSingle">
     <input type="hidden" name="iSaveSingle" value="1">
     <input type="hidden" name="strDBField" value="">
     <input type="hidden" name="strFormValue" value="">
     <input type="hidden" name="iIsString" value="0">    
    <input type="hidden" name="cb1Field" value="">
    <input type="hidden" name="cb1Value" value="">    
    <input type="hidden" name="cb2Field" value="">
    <input type="hidden" name="cb2Value" value="">    
</form>


<!-- Real Form Here  [REPLACE BELOW WITH YOUR EXISTING FORM, JUST APPLY THE BUTTON ONCLICK SYNTAX TO THE SAVE BUTTONS]-->
<form name="frmRealForm" method="POST">
     <input type="hidden" name="iSaveAll" value="1">
     <textarea name="txtTextField"><%= Name1 %></textarea>
     <input type="checkbox" value="1" name="cb1" <% if cb1 = true then %>checked<% end if %>>
     <input type="checkbox" value="1" name="cb2" <% if cb2 = true then %>checked<% end if %>>
   
  <input type="button" value="Save" onclick="fSaveSingle('Name1','txtTextField',1,'11a','cb1','11b','cb2')">
       <br>
  <textarea  name="txtTextField2"><%= Position_in_Firm %></textarea>
<input type="checkbox" value="1" name="cb3" <% if cb3 = true then %>checked<% end if %>>
<input type="checkbox" value="1" name="cb4" <% if cb4 = true then %>checked<% end if %>>
 <input type="button" value="Save" onclick="fSaveSingle('Position_in_Firm','txtTextField2',1,'12a','cb3','12b','cb4')">
     <br>
      <textarea name="txtTextField3"><%= Percentage_of_Ownership_I %></textarea>
     <input type="checkbox" value="1" name="cb5" <% if cb5 = true then %>checked<% end if %>>
     <input type="checkbox" value="1" name="cb6" <% if cb6 = true then %>checked<% end if %>>
  <input type="button" value="Save" onclick="fSaveSingle('Percentage_of_Ownership_I','txtTextField3',1,'13a','cb5','13b','cb6')">

  <br>
   <input type="submit" value="SAVE ALL">
</form>
 
 
 
0
 
LVL 9

Expert Comment

by:AgentSmith007
ID: 12657989
SORRY! Syntax issue...use this one:

<!--;window.location = 'form1.asp?M_USERNAME=<% response.write (session("user"))%>'; -->
<script language="javascript">
function fSaveSingle(strDBField,strFormValue,iIsString,chk1Field,chk1Value,chk2Field,chk2Value){
     iSubmit = 1;
     if (iSubmit == 1){
          if (document.forms.frmRealForm[strFormValue].value == ""){
               alert("This field cannot be empty.");
               iSubmit = 0;
          }
     }
      if (iSubmit == 1){
          document.forms.frmSaveSingle.strDBField.value = strDBField;
          document.forms.frmSaveSingle.strFormValue.value = document.forms.frmRealForm[strFormValue].value;
          document.forms.frmSaveSingle.iIsString.value = iIsString;
            //below code is added
               document.forms.frmSaveSingle.cb1Field.value = chk1Field;
               document.forms.frmSaveSingle.cb2Field.value = chk2Field;              
          document.forms.frmSaveSingle.cb1Value.value = 0;
          document.forms.frmSaveSingle.cb2Value.value = 0;
          if (document.forms.frmRealForm[chk1Value].checked){
               document.forms.frmSaveSingle.cb1Value.value = 1;
          }
          if (document.forms.frmRealForm[chk2Value].checked){
               document.forms.frmSaveSingle.cb2Value.value = 1;
          }          
        document.forms.frmSaveSingle.submit();
     }
}
</script>
<%
'Declare connection object
 Dim straccessdb, conn, strcon
 strAccessDB = "db1.mdb"
 Set Conn = Server.CreateObject("ADODB.Connection")
 strCon = "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=; DBQ=" & Server.MapPath(strAccessDB)
 conn.Open strCon

'Function to make SQL statements not fail w/ special character(s)
function fQueryFriendly(strVar)
      strTemp = strVar
      strTemp = Replace(strTemp,"'","''")
      fQueryFriendly = strTemp
end function

'Set current user
dim M_USERNAME
M_USERNAME = session("user")
       
if request.form("iSaveSingle") = 1 then
     'Saving a single "row"
     strFieldName = request.form("strDBField")
     strFieldValue = request.form("strFormValue")
     iIsString = request.form("iIsString")
      strQuote = ""
     if iIsString = 1 then
          strQuote = "'"
     end if
     cb1 = false
     cb2 = false
     if cint(request.form("cb1Value")) = 1 then
          cb1 = true
     end if
     if cint(request.form("cb2Value")) = 1 then
          cb2 = true
     end if
     
     strSQL = "UPDATE check "
     strSQL = strSQL & "SET " & strFieldName & " = " & strQuote & fQueryFriendly(strFieldValue) & strQuote & " "
     strSQL = strSQL & ", " & request.form("cb1Field") & " = " & cb1 & " "
     strSQL = strSQL & ", " & request.form("cb2Field") & " = " & cb2 & " "
     strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
     conn.execute(strSQL)
     'response.write("<!-- [JAVASCRIPT POPUP WINDOW CODE HERE FOR PDF FILE] -->");
end if

if request.form("iSaveAll") = "1" then
'Set checkbox values
cb1 = False
cb2 = False
cb3 = False
cb4 = False
cb5 = False
cb6 = False
if cint(request.form("cb1")) = 1 then
     cb1 = True
end if

if cint(request.form("cb2")) = 1 then
     cb2 = True
end if

if cint(request.form("cb3")) = 1 then
     cb3 = True
end if

if cint(request.form("cb4")) = 1 then
     cb4 = True
end if
  if cint(request.form("cb5")) = 1 then
     cb5 = True
end if

if cint(request.form("cb6")) = 1 then
     cb6 = True
end if
     'Saving entire form
     strSQL = "UPDATE check SET "
     strSQL = strSQL & "Name1 = '" & fQueryFriendly(request.form("txtTextField")) & "'"
     strSQL = strSQL & ",Position_in_Firm = '" & fQueryFriendly(request.form("txtTextField2")) & "'"
     strSQL = strSQL & ",Percentage_of_Ownership_I = '" & fQueryFriendly(request.form("txtTextField3")) & "'"
      'add check boxes
     strSQL = strSQL & ", 11a = " & cb1 & " "
     strSQL = strSQL & ", 11b = " & cb2 & " "
     strSQL = strSQL & ", 12a = " & cb3 & " "
     strSQL = strSQL & ", 12b = " & cb4 & " "
     strSQL = strSQL & ", 13a = " & cb5 & " "
     strSQL = strSQL & ", 13b = " & cb6 & " "
      strSQL = strSQL & "WHERE M_USERNAME = '" & session("user") & "'"
     conn.execute(strSQL)
End If


'read from db
strSQL ="SELECT * FROM check WHERE M_USERNAME = '" & Session("user") & "'"
Set oRS = conn.Execute(strSQL)
while not oRS.Eof
     'get the data
     Name1 = oRS("Name1")
     Position_in_Firm = oRS("Position_in_Firm")
     Percentage_of_Ownership_I = oRS("Percentage_of_Ownership_I")
      If  oRS("11a") Then
          cb1=true
     end if
     If  oRS("11b") Then
          cb2=true
     end if
     If  oRS("12a") Then
          cb3=true
     end if
     If  oRS("12b") Then
          cb4=true
     end if
           If  oRS("13a") Then
          cb5=true
     end if
     If  oRS("13b") Then
          cb6=true
     end if
      oRS.MoveNext
wend
oRS.close
set oRS = nothing
%>
<!-- Hidden Form Here -->
<form method="POST" name="frmSaveSingle">
     <input type="hidden" name="iSaveSingle" value="1">
     <input type="hidden" name="strDBField" value="">
     <input type="hidden" name="strFormValue" value="">
     <input type="hidden" name="iIsString" value="0">    
    <input type="hidden" name="cb1Field" value="">
    <input type="hidden" name="cb1Value" value="">    
    <input type="hidden" name="cb2Field" value="">
    <input type="hidden" name="cb2Value" value="">    
</form>


<!-- Real Form Here  [REPLACE BELOW WITH YOUR EXISTING FORM, JUST APPLY THE BUTTON ONCLICK SYNTAX TO THE SAVE BUTTONS]-->
<form name="frmRealForm" method="POST">
     <input type="hidden" name="iSaveAll" value="1">
     <textarea name="txtTextField"><%= Name1 %></textarea>
     <input type="checkbox" value="1" name="cb1" <% if cb1 = true then %>checked<% end if %>>
     <input type="checkbox" value="1" name="cb2" <% if cb2 = true then %>checked<% end if %>>
   
  <input type="button" value="Save" onclick="fSaveSingle('Name1','txtTextField',1,'11a','cb1','11b','cb2')">
       <br>
  <textarea  name="txtTextField2"><%= Position_in_Firm %></textarea>
<input type="checkbox" value="1" name="cb3" <% if cb3 = true then %>checked<% end if %>>
<input type="checkbox" value="1" name="cb4" <% if cb4 = true then %>checked<% end if %>>
 <input type="button" value="Save" onclick="fSaveSingle('Position_in_Firm','txtTextField2',1,'12a','cb3','12b','cb4')">
     <br>
      <textarea name="txtTextField3"><%= Percentage_of_Ownership_I %></textarea>
     <input type="checkbox" value="1" name="cb5" <% if cb5 = true then %>checked<% end if %>>
     <input type="checkbox" value="1" name="cb6" <% if cb6 = true then %>checked<% end if %>>
  <input type="button" value="Save" onclick="fSaveSingle('Percentage_of_Ownership_I','txtTextField3',1,'13a','cb5','13b','cb6')">

  <br>
   <input type="submit" value="SAVE ALL">
</form>
 
 
 
0
 

Author Comment

by:Melfeky
ID: 12658056
well that is the best solution to this form
0
 

Author Comment

by:Melfeky
ID: 12658121
>>> if (iSubmit == 1){
          if (document.forms.frmRealForm[strFormValue].value == ""){
               alert("This field cannot be empty.");
               iSubmit = 0;
          }
     }
//////////

can we make this alert only when the user selects the left checkbox
as the left is "yes" and the right is "no".
so if the user checks the left checkbox without adding data in the text area he should get this alert, but if he chooses the right checkbox and click the save button he should get nothing.
,

if not could u just remove it.
0
 
LVL 9

Accepted Solution

by:
AgentSmith007 earned 1600 total points
ID: 12658165
Sure, I'll remove it. It's going to be yes/no i would recommend making those checkboxes radio buttons, but that's a discussion for a different thread:

change that entire function to this:

function fSaveSingle(strDBField,strFormValue,iIsString,chk1Field,chk1Value,chk2Field,chk2Value){
        document.forms.frmSaveSingle.strDBField.value = strDBField;
        document.forms.frmSaveSingle.strFormValue.value = document.forms.frmRealForm[strFormValue].value;
        document.forms.frmSaveSingle.iIsString.value = iIsString;
       &n