Form reloads

Discussion in 'ASP General' started by JJ, Aug 18, 2003.

  1. JJ

    JJ Guest

    Hi All,

    When someone selects a value in a select on a form I want to show the
    same form with another select with certain values depending on first select.
    How can I do this? Should I keep acouple of arrays loaded with the second
    selects values not to be shown till selected in first or what other means?

    Also how do you reload the current form to show maybe a nex field or select
    box?

    Thanks,

    JJ
    JJ, Aug 18, 2003
    #1
    1. Advertising

  2. JJ

    Curt_C [MVP] Guest

    it's a clientside event but have the onChange() trigger a form.submit()

    --
    ----------------------------------------------------------
    Curt Christianson (Software_AT_Darkfalz.Com)
    Owner/Lead Designer, DF-Software
    http://www.Darkfalz.com
    ---------------------------------------------------------
    ...Offering free scripts & code snippits for everyone...
    ---------------------------------------------------------


    "JJ" <> wrote in message
    news:...
    > Hi All,
    >
    > When someone selects a value in a select on a form I want to show the
    > same form with another select with certain values depending on first

    select.
    > How can I do this? Should I keep acouple of arrays loaded with the second
    > selects values not to be shown till selected in first or what other means?
    >
    > Also how do you reload the current form to show maybe a nex field or

    select
    > box?
    >
    > Thanks,
    >
    > JJ
    >
    >
    Curt_C [MVP], Aug 19, 2003
    #2
    1. Advertising

  3. JJ

    Bullschmidt Guest

    You can use dependent listboxes for example to let a user choose a rep
    in a reps listbox and then have only the customers for that rep be shown
    in the customers listbox.

    You can see an example of this on the ASP Web database demo on my site
    www.bullschmidt.com/login.asp and then go to the Invoices dialog and
    choose a rep in the listbox and notice that the page is posted to
    itself, the customers listbox then gets the focus, and the customers
    listbox only contains the customers for that rep.

    I'd suggest having the onchange event for the first listbox (called
    RepID) use JavaScript to submit the page (assuming the page is being
    posted back to itself anyway) and then if the page is a post, show the
    extra info in the second listbox.

    Example:
    <select name="RepID" size="1" onchange="RefreshPg('CustID');">

    And the SQL for the second listbox (called CustID) would be something
    like this:
    strSQL = "SELECT CustID "
    strSQL = strSQL & "FROM tblCust "
    strSQL = strSQL & "WHERE (1=1) "
    If Request.Form("RepID") <> "" Then
    strSQL = strSQL & "AND (CustUserID=" & Chr(39) & Request.Form("RepID")
    & Chr(39) & ") "
    End If
    strSQL = strSQL & "ORDER BY CustID"

    And on the form have a hidden field which will contain the name of the
    field to be given the focus when the page is reopened.

    Example:
    <input type="hidden" name="FocusedFldName" value="<%=
    Request.Form("FocusedFldName") %>">

    And somewhere on the page:
    <% ' Set focus.
    If Request.Form("FocusedFldName") <> "" Then
    ' Set focus based on FocusedFldName.
    %>
    <script type="text/javascript">document.frmMain.<%=
    Request.Form("FocusedFldName") %>.focus();</script>
    <% Else
    ' Set focus.
    %>
    <script type="text/javascript">document.frmMain.RepID.focus();</script>
    <% End If %>

    And here's the JavaScript function to submit the page for this purpose:

    function RefreshPg(pstrFldName) {
    // Purpose: Refresh pg. to update other fld(s) based on selection.
    // Remarks: Used by listbox's onchange.
    // Assumes existence of document.frmMain.FocusedFldName hidden fld.

    // Set focused fld for when come back.
    document.frmMain.FocusedFldName.value = pstrFldName;

    // Msg.
    alert("Refreshing page to update other field(s) based on your
    selection.");

    // Submit pg to itself to refresh other combo based on this combo.
    document.frmMain.submit();
    }

    And here are some final notes of clarification.

    FocusedFldName is the name of a hidden field on the form. It is usually
    blank but after the user changes the parent listbox (called RepID)
    JavaScript code puts in the name of the child listbox (called CustID)
    into the hidden field (called FocusedFldName) on the form.

    Then when the page is reopened JavaScript sets the focus on the name of
    the field (i.e. the name of the child listbox) contained in the hidden
    field. Thus the focus is set on the CustID field (instead of the RepID
    field which gets the focus when the form is FIRST opened).

    And if the RepID field in the database is a numeric field then the
    Chr(39) stuff is not needed so this:
    strSQL = strSQL & "AND (CustUserID=" & Chr(39) & Request.Form("RepID")
    & Chr(39) & ") "
    Should be changed to this:
    strSQL = strSQL & "AND (CustUserID=" & Request.Form("RepID") & ") "

    Best regards,
    J. Paul Schmidt, Freelance ASP Web Developer
    http://www.Bullschmidt.com
    ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Bullschmidt, Aug 22, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christian
    Replies:
    0
    Views:
    372
    Christian
    Jul 17, 2003
  2. VB Programmer

    Why swf reloads every time?

    VB Programmer, May 13, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    361
    VB Programmer
    May 13, 2005
  3. SevDer

    AppDomain randomly reloads

    SevDer, Jan 4, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    1,052
    SevDer
    Jan 4, 2006
  4. coffee_man

    remember form field input over reloads

    coffee_man, Oct 6, 2005, in forum: Javascript
    Replies:
    3
    Views:
    166
    Erwin Moller
    Oct 6, 2005
  5. AC
    Replies:
    1
    Views:
    103
Loading...

Share This Page