Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Feb 2007
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    update a hidden form value from a list box

    Hi guys & gals,

    I have a page with 2 forms on, namely form1 and form2!!

    In form1 there is a listbox with a drop down of IDs. Now if the user selects a different ID in that list, form2 hidden variable (qualstatus) needs to be updated with the new ID which was selected in form1. I have tried the following.

    function changequal() {
    document.form2.qualstatus.value = document.form1.qualstatus.value
    }

    with a

    <select name="qualstatus" id="qualstatus" onChange="changequal()">

    however this does not seem to update the value of

    <input name="qualstatus" type="hidden" id="qualstatus" value="<%=(rsAction.Fields.Item("qualStatusID").Value)%>">

    Any ideas of get arounds would be great!

    thanks

  • #2
    Regular Coder BonRouge's Avatar
    Join Date
    Mar 2006
    Location
    Sendai, Japan
    Posts
    328
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It looks OK. Can you show us the page?

  • #3
    New Coder
    Join Date
    Feb 2007
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    full page code is.....

    had to edit some of the code to fit into one post......

    --------------------------------------------

    <%@LANGUAGE="VBSCRIPT"%>
    <!--#include file="../../Connections/cnnHOA.asp" -->
    <%
    ' *** Edit Operations: declare variable

    MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
    If (Request.QueryString <> "") Then
    MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
    End If

    ' boolean to abort record edit
    MM_abortEdit = false

    ' query string to execute
    MM_editQuery = ""
    %>
    <%
    ' *** Update Record: set variables

    If (CStr(Request("MM_update")) = "form1" And CStr(Request("MM_recordId")) <> "") Then

    MM_editConnection = MM_cnnHOA_STRING
    MM_editTable = "dbo.tblActions"
    MM_editColumn = "callbackID"
    MM_recordId = "" + Request.Form("MM_recordId") + ""
    MM_editRedirectUrl = "view.asp"
    MM_fieldsStr = "callDate|value|CallTime|value|fld_comment|value|select|value|callfor|value|isComplete|value"
    MM_columnsStr = "callDate|',none,NULL|CallTime|',none,''|fld_comment|',none,''|actiontype|',none,''|callfor|none,non e,NULL|actioncomplete|none,1,0"

    ' create the MM_fields and MM_columns arrays
    MM_fields = Split(MM_fieldsStr, "|")
    MM_columns = Split(MM_columnsStr, "|")

    ' set the form values
    For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
    Next

    ' append the query string to the redirect URL
    If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
    If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
    MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
    Else
    MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
    End If
    End If

    End If
    %>
    <%
    ' *** Update Record: construct a sql update statement and execute it

    If (CStr(Request("MM_update")) <> "" And CStr(Request("MM_recordId")) <> "") Then

    ' create the sql update statement
    standard DMX code here

    If (Not MM_abortEdit) Then
    ' execute the update
    Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    'before finsih lets update the qual status
    Set MM_editCmd2 = Server.CreateObject("ADODB.Command")
    MM_editCmd2.ActiveConnection = MM_editConnection
    MM_editCmd2.CommandText = "UPDATE dbo.tblClients SET Trig_QualifiedStatus="&request("qualstatus")&" WHERE clientID='"&request("clientID")&"'"
    MM_editCmd2.Execute
    MM_editCmd2.ActiveConnection.Close

    If (MM_editRedirectUrl <> "") Then
    Response.Redirect(MM_editRedirectUrl)
    End If
    End If

    End If
    %>
    <%
    if request("save") = "yes" then
    'update to make complete
    Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_cnnHOA_STRING
    MM_editCmd.CommandText = "UPDATE dbo.tblActions SET actioncomplete=1 WHERE callbackID='"&request("callbackID")&"'"
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    'now update the QUAL STATUS in client table

    Set MM_editCmd2 = Server.CreateObject("ADODB.Command")
    MM_editCmd2.ActiveConnection = MM_cnnHOA_STRING
    MM_editCmd2.CommandText = "UPDATE dbo.tblClients SET Trig_QualifiedStatus='"&request("qualstatus")&"' WHERE clientID='"&request("callbackID")&"'"
    MM_editCmd2.Execute
    MM_editCmd2.ActiveConnection.Close
    end if
    %>
    <%

    Dim cmdAction__callbackID
    cmdAction__callbackID = ""
    if(Request("callbackID") <> "") then cmdAction__callbackID = Request("callbackID")

    %>

    <%

    set cmdAction = Server.CreateObject("ADODB.Command")
    cmdAction.ActiveConnection = MM_cnnHOA_STRING
    cmdAction.CommandText = "iwantthatvillacom.spActionLookUp"
    cmdAction.CommandType = 4
    cmdAction.CommandTimeout = 0
    cmdAction.Prepared = true
    cmdAction.Parameters.Append cmdAction.CreateParameter("@RETURN_VALUE", 3, 4)
    cmdAction.Parameters.Append cmdAction.CreateParameter("@callbackID", 3, 1,10,cmdAction__callbackID)
    set rsAction = cmdAction.Execute
    rsAction_numRows = 0

    %>
    <%
    Dim rsAdmin
    Dim rsAdmin_numRows

    Set rsAdmin = Server.CreateObject("ADODB.Recordset")
    rsAdmin.ActiveConnection = MM_cnnHOA_STRING
    rsAdmin.Source = "SELECT * FROM dbo.tblAdmin"
    rsAdmin.CursorType = 0
    rsAdmin.CursorLocation = 2
    rsAdmin.LockType = 1
    rsAdmin.Open()

    rsAdmin_numRows = 0
    %>
    <%
    Dim rsQual
    Dim rsQual_numRows

    Set rsQual = Server.CreateObject("ADODB.Recordset")
    rsQual.ActiveConnection = MM_cnnHOA_STRING
    rsQual.Source = "SELECT * FROM dbo.tblQualStatus ORDER BY qualName ASC"
    rsQual.CursorType = 0
    rsQual.CursorLocation = 2
    rsQual.LockType = 1
    rsQual.Open()

    rsQual_numRows = 0
    %>
    <SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
    function DoDateTime(str)
    DateArray=Split(str,"/")
    if left(DateArray(0),1) = "0" then
    DateArray(0) = Replace(DateArray(0),"0","")
    if Left(DateArray(1),1) = "0" then
    DateArray(1) = Replace(DateArray(1),"0","")
    end if
    end if
    if left(DateArray(1),1) = "0" then
    DateArray=Split(str,"/")
    DateArray(1) = Replace(DateArray(1),"0","")
    end if
    str = DateArray(0) & "/" & DateArray(1) & "/" & DateArray(2) & " "
    DoDateTime = str
    End Function
    </SCRIPT>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Back Office</title>
    <link href="../../css/admin.css" rel="stylesheet" type="text/css">
    <script language="JavaScript" src="../js/ts_picker.js"></script>
    <script>
    <!--

    function changequal() {
    document.form2.qualstatus.value = document.form1.qualstatus.value
    }

    function charRemaining(tField, nField, maxAllowed) {
    if (tField.value.length > maxAllowed) {
    tField.value = tField.value.substring(0, maxAllowed);
    }
    nField.value = maxAllowed - tField.value.length;
    }
    if (window != window.top) top.location.href = location.href;

    function MM_findObj(n, d) { //v4.01
    var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
    }

    function YY_checkform() { //v4.71
    //copyright (c)1998,2002 Yaromat.com
    var a=YY_checkform.arguments,oo=true,v='',s='',err=false,r,o,at,o1,t,i,j,ma,rx,cd,cm,cy,dte,at;
    for (i=1; i<a.length;i=i+4){
    if (a[i+1].charAt(0)=='#'){r=true; a[i+1]=a[i+1].substring(1);}else{r=false}
    o=MM_findObj(a[i].replace(/\[\d+\]/ig,""));
    o1=MM_findObj(a[i+1].replace(/\[\d+\]/ig,""));
    v=o.value;t=a[i+2];
    if (o.type=='text'||o.type=='password'||o.type=='hidden'){
    if (r&&v.length==0){err=true}
    if (v.length>0)
    if (t==1){ //fromto
    ma=a[i+1].split('_');if(isNaN(v)||v<ma[0]/1||v > ma[1]/1){err=true}
    } else if (t==2){
    rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");if(!rx.test(v))err=true;
    } else if (t==3){ // date
    ma=a[i+1].split("#");at=v.match(ma[0]);
    if(at){
    cd=(at[ma[1]])?at[ma[1]]:1;cm=at[ma[2]]-1;cy=at[ma[3]];
    dte=new Date(cy,cm,cd);
    if(dte.getFullYear()!=cy||dte.getDate()!=cd||dte.getMonth()!=cm){err=true};
    }else{err=true}
    } else if (t==4){ // time
    ma=a[i+1].split("#");at=v.match(ma[0]);if(!at){err=true}
    } else if (t==5){ // check this 2
    if(o1.length)o1=o1[a[i+1].replace(/(.*\[)|(\].*)/ig,"")];
    if(!o1.checked){err=true}
    } else if (t==6){ // the same
    if(v!=MM_findObj(a[i+1]).value){err=true}
    }
    } else
    if (!o.type&&o.length>0&&o[0].type=='radio'){
    at = a[i].match(/(.*)\[(\d+)\].*/i);
    o2=(o.length>1)?o[at[2]];
    if (t==1&&o2&&o2.checked&&o1&&o1.value.length/1==0){err=true}
    if (t==2){
    oo=false;
    for(j=0;j<o.length;j++){oo=oo||o[j].checked}
    if(!oo){s+='* '+a[i+3]+'\n'}
    }
    } else if (o.type=='checkbox'){
    if((t==1&&o.checked==false)||(t==2&&o.checked&&o1&&o1.value.length/1==0)){err=true}
    } else if (o.type=='select-one'||o.type=='select-multiple'){
    if(t==1&&o.selectedIndex/1==0){err=true}
    }else if (o.type=='textarea'){
    if(v.length<a[i+1]){err=true}
    }
    if (err){s+='* '+a[i+3]+'\n'; err=false}
    }
    if (s!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+s)}
    document.MM_returnValue = (s=='');
    }
    //-->
    </script>
    <style type="text/css">
    <!--
    .style1 {
    color: #FF0000;
    }
    -->
    </style>
    </head>
    <body>
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td class="main-table" align="left" valign="top"><h1>Viewing action number <%=request("callbackID")%></h1>
    <p>
    <%=rsAction.Fields.Item("name_title").Value%>&nbsp;<%=rsAction.Fields.Item("name_firstname").Value%> &nbsp;<%=rsAction.Fields.Item("name_surname").Value%>, <%=rsAction.Fields.Item("Address_Tel").Value%>, <%=rsAction.Fields.Item("Address_Mobile").Value%><br>
    <%=rsAction.Fields.Item("EmailAddress").Value%>
    </p>
    <br>
    <form ACTION="<%=MM_editAction%>" METHOD="POST" name="form1">
    <table width="100%" border="0" cellspacing="0" cellpadding="5">
    <tr>
    <td width="13%" bgcolor="#CCCCFF"><strong> Date of action </strong></td>
    <td width="27%" bgcolor="#CCCCFF"><input name="callDate" type="text" id="callDate" value="<%= DoDateTime((rsAction.Fields.Item("callDate").Value)) %>" size="10" readonly="">
    &nbsp;&nbsp;<a href="javascript:show_calendar('document.form1.callDate', document.form1.callDate.value);"><img src="../js/cal.gif" width="16" height="16" border="0"></a></td>
    <td width="17%" bgcolor="#CCCCFF"><strong>Action Time </strong></td>
    </tr>
    <tr>
    <td valign="top" bgcolor="#CCCCFF"><strong>Reason / Details </strong></td>
    <td bgcolor="#CCCCFF" colspan="3"><textarea name="fld_comment" cols="70" rows="8" onKeyDown="charRemaining(this.form.fld_comment, this.form.lcounter, 5000);" onKeyUp="charRemaining(this.form.fld_comment, this.form.lcounter, 5000);" ><%=(rsAction.Fields.Item("fld_comment").Value)%></textarea>
    </p>
    <p>
    <input name="lcounter" type=text id="lcounter" value="5000" size="6" maxlength="5" readonly>
    Characters remaining </p></td>
    </tr>
    <tr>
    <td bgcolor="#FF9966"><strong>Action type </strong></td>
    <td bgcolor="#FF9966"><select name="select">
    <option value="callback" selected <%If (Not isNull((rsAction.Fields.Item("actiontype").Value))) Then If ("callback" = CStr((rsAction.Fields.Item("actiontype").Value))) Then Response.Write("selected=""selected""") : Response.Write("")%>>Callback</option>
    <option value="action" <%If (Not isNull((rsAction.Fields.Item("actiontype").Value))) Then If ("action" = CStr((rsAction.Fields.Item("actiontype").Value))) Then Response.Write("selected=""selected""") : Response.Write("")%>>Action or To Do</option>
    </select></td>
    <td bgcolor="#FF9966"><strong>Who for? </strong></td>
    <td bgcolor="#FF9966"><select name="callfor" id="callfor">
    <option value="none" <%If (Not isNull((rsAction.Fields.Item("callfor").Value))) Then If ("none" = CStr((rsAction.Fields.Item("callfor").Value))) Then Response.Write("selected=""selected""") : Response.Write("")%>>Select</option>
    <%
    While (NOT rsAdmin.EOF)
    %>
    <option value="<%=(rsAdmin.Fields.Item("adminID").Value)%>" <%If (Not isNull((rsAction.Fields.Item("callfor").Value))) Then If (CStr(rsAdmin.Fields.Item("adminID").Value) = CStr((rsAction.Fields.Item("callfor").Value))) Then Response.Write("selected=""selected""") : Response.Write("")%> ><%=(rsAdmin.Fields.Item("actualname").Value)%></option>
    <%
    rsAdmin.MoveNext()
    Wend
    If (rsAdmin.CursorType > 0) Then
    rsAdmin.MoveFirst
    Else
    rsAdmin.Requery
    End If
    %>
    </select></td>
    </tr>
    <tr>
    <td bgcolor="#99CCCC"><strong>Qualified Status </strong></td>
    <td bgcolor="#99CCCC"><select name="qualstatus" id="qualstatus" <% if (rsAction.Fields.Item("actioncomplete").Value) = False then response.Write("onChange=""changequal()""")%>>
    <%
    While (NOT rsQual.EOF)
    %>
    <option <% if (rsAction.Fields.Item("qualStatusID").Value)=(rsQual.Fields.Item("qualStatusID").Value) then response.write("selected")%> style="background-color:<%=(rsQual.Fields.Item("qualColor").Value)%>" value="<%=(rsQual.Fields.Item("qualStatusID").Value)%>"><%=(rsQual.Fields.Item("qualName").Value)%></option>
    <%
    rsQual.MoveNext()
    Wend
    If (rsQual.CursorType > 0) Then
    rsQual.MoveFirst
    Else
    rsQual.Requery
    End If
    %>
    </select>
    </td>
    <td bgcolor="#99CCCC" colspan="2">**Note: Changing the qualified status here will also update master view**</td>
    </tr>

    <tr>
    <td bgcolor="#FF3300">&nbsp;</td>
    <td bgcolor="#FF3300"><input name="Submit2" type="submit" class="boldmed" onClick="YY_checkform('form1[0]','callDate','#q','0','Your must select a date for the callback','callfor','#q','1','You must select who the callback is for','fld_comment','1','1','You must enter a reason for the callback');return document.MM_returnValue" value="Save changes"></td>
    <td bgcolor="#FF3300" colspan="2">&nbsp;</td>
    </tr>
    </table>
    <input type="hidden" name="MM_update" value="form1">
    <input type="hidden" name="MM_recordId" value="<%= rsAction.Fields.Item("callbackID").Value %>">
    <input name="clientID" type="hidden" id="clientID" value="<%= rsAction.Fields.Item("clientID").Value %>">
    <input name="callbackID" type="hidden" id="callbackID" value="<%= rsAction.Fields.Item("callbackID").Value %>">
    </form>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <% if (rsAction.Fields.Item("actioncomplete").Value) = False then%><td>

    <form name="form2" action="view.asp">
    <p class="style1">Only click the "DONE" button below when you have COMPLETED this action or CB, <br>
    if not use "save changes" and then "close window"</p>
    <p>
    <input name="Submit" type="submit" class="boldmed" value="DONE">
    <input name="save" type="hidden" id="save" value="yes">
    <input name="callbackID" type="hidden" id="callbackID" value="<%=(rsAction.Fields.Item("callbackID").Value)%>">
    <input name="clientID" type="hidden" id="clientID" value="<%=rsAction.Fields.Item("clientID").Value %>">
    <input name="qualstatus" type="hidden" id="qualstatus" value="<%=(rsAction.Fields.Item("qualStatusID").Value)%>">
    </p>
    </form>
    &nbsp;</td> <% end if %>
    <td>
    <form name="form3" method="post" action="view.asp">
    <input name="Submit" type="submit" class="boldmed" value="Close Window" onClick="javascript:window.close();">
    <input name="callbackID" type="hidden" id="callbackID" value="<%=(rsAction.Fields.Item("callbackID").Value)%>">
    </form></td>
    </tr>
    </table></td>
    </tr>
    </table>
    </body>
    </html>

  • #4
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,302
    Thanks
    28
    Thanked 276 Times in 270 Posts
    Quote Originally Posted by lozhowlett View Post
    <select name="qualstatus" id="qualstatus" onChange="changequal()">

    however this does not seem to update the value of

    <input name="qualstatus" type="hidden" id="qualstatus" value="<%=(rsAction.Fields.Item("qualStatusID").Value)%>">
    It is incorrect HTML to have two elements with the same ID. Any given ID name may only be used once per document. The concept is like that of a real ID; for example, you don’t have two people with identical driver licenses. Using duplicate IDs in a single document is likely to be problematic.

    I would also not use that outdated form method for getting at a specific element. document.getElementById("qualstatus") is more direct.

    Quote Originally Posted by lozhowlett View Post
    full page code is.....

    had to edit some of the code to fit into one post......
    When you post code, try using the forum’s [code] tags and turning off emoticons.
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #5
    New Coder
    Join Date
    Feb 2007
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for that. I have now tried

    Code:
    function changequal() {
    	document.getElementById("qualstatus2") = document.getElementById("qualstatus")
    }
    and updated the form variable. However this still does not see to update the id. Is there anyway to get a read out of what has changed when the function is run? Ie. Alert:New value of qualstatus2 is....

    thanks

  • #6
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,302
    Thanks
    28
    Thanked 276 Times in 270 Posts
    Quote Originally Posted by lozhowlett View Post
    thanks for that. I have now tried

    Code:
    function changequal() {
    	document.getElementById("qualstatus2") = document.getElementById("qualstatus")
    }
    You’re setting one element equal to another when I suspect that you want their values to be equal. Try this:

    Code:
    document.getElementById("qualstatus2").value = document.getElementById("qualstatus").value;
    Quote Originally Posted by lozhowlett View Post
    Is there anyway to get a read out of what has changed when the function is run? Ie. Alert:New value of qualstatus2 is....
    Code:
    function changeEqual() {
      alert("Old Value: " + document.getElementById("qualstatus2").value);
      document.getElementById("qualstatus2").value = document.getElementById("qualstatus").value;
      alert("New Value: " + document.getElementById("qualstatus2").value);
    }
    Last edited by Arbitrator; 05-16-2007 at 03:37 PM. Reason: Updated example function.
    For every complex problem, there is an answer that is clear, simple, and wrong.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •