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 to the CF scene
    Join Date
    Aug 2005
    Location
    PA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    using onChange page gets stuck in refresh loop

    I have a page where I have a few different select boxes with onChange. If you change the select once and give it a value, everything works fine. If you then want to change it to another answer, it gets stuck in a refreshing loop. It just keeps refreshing the page and all that I can do is click the refresh button at the top. If I click this button, the page refreshes back to the first option picked.

    Does anyone know how I can set up my page so that I can change the select answer and the page will update properly. The code that I am using:
    The java at the bttom of the page.
    <script type="text/javascript">
    function updateForms() {
    document.forms['page1'].submit();
    }
    </script>

    The start of the select box:
    Response.Write "<select onchange=""updateForms()"" name=""txtIBMName"" class=""medium"" style=""font-family:Verdana, Arial;font-size:10"">" & chr(13)

    Any help is greatly appreciated.
    No matter which way the winds blows, it's still gonna get ya..

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    This code should not hurt anything.
    What else do you have in there that you didn't post, such as how you select the option?

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New to the CF scene
    Join Date
    Aug 2005
    Location
    PA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    At the top of the page, I set the different variables to session variables.
    The body:
    <body onLoad="setTimeout('restoreValues()',50);setTimeout('watchTimes()', 1200);">

    Then I use the select statement like I posted earlier:
    Response.Write "<select onchange=""updateForms()"" name=""txtIBMName"" class=""medium"" style=""font-family:Verdana, Arial;font-size:10"">" & chr(13)

    Just a drop down box that when an option is select, the page is suppose to refresh with the new option selected in the box.
    I do have about 4 different select statements on the page, all using onchange.

    The end of the page:
    <script type="text/javascript">

    function updateForms() {
    //document.forms['page1'].submit();
    //window.location="http://intranet.tstechnet.local/spreadsheets/decisionPage1.asp";
    //window.location.reload( true );
    }

    function restoreValues() {
    if ('<% response.write Request.Form("txtIBMName") %>' != ''){ document.forms['page1'].txtIBMName.value = '<% response.write session("IBMName") %>';}
    if ('<% response.write Request.Form("txtIBMQuantity") %>' != ''){ document.forms['page1'].txtIBMQuantity.value = '<% response.write Request.Form("txtIBMQuantity") %>';}
    }

    var lastTime = '';

    function watchTimes(){

    if (lastTime != ''){
    if (lastTime != document.forms['page1'].txtIBMName.value){ document.forms['page1'].submit(); }
    }else{
    lastTime = document.forms['page1'].txtIBMName.value;
    }

    setTimeout('watchTimes()', 1000);

    }
    </script>

    This is all I have in my sight. It works correctly the first time it is run. After that first time, if you want to change the select, it just gets stuck. I have no idea. Please help.
    No matter which way the winds blows, it's still gonna get ya..

  • #4
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Okay, I figured as much.
    You're using client-side code to change the values. So, onchange fires which submits the form. And it happens all over again.

    Why are you using client-side script for setting up the selects when you have a server-side language available?
    This is not the normal way such things are done. The selects would be set up with ASP.

    That said, you need to put code in your function that does the selection to set a global variable to some value that means it changed that select field (not the user), then have your onchange function check for that before it submits. Or stop event propagation. Or something. Didn't think it through yet.
    Whatever way you do it, you need to distinguish your code changing the selects from the user changing them.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #5
    New to the CF scene
    Join Date
    Aug 2005
    Location
    PA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Um. I coded it that way because that is all I know how to do. Not really sure what you are talking about. I have the session variables that are being set with the values. I am kind of new to this stuff. If you wouldnt mind explaining this a little more, I would greatly appreciate it. Thank you.
    Last edited by purpleCraze; 09-21-2005 at 07:18 PM.
    No matter which way the winds blows, it's still gonna get ya..

  • #6
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Hey, no problem.
    Sometimes there's a reason people code something a certain way.

    If I were trying to set select elements to the values in a session, and I was using ASP to generate the page to begin with, I would do something like

    Code:
    <%
    ' get the session stuff and so on
    myVar = Session("whatever")
    %>
    
    <select name="mySelect">
    <option value="one"<% if myVar="one" then response.write "selected" end if%>>one</option>
    <option value="two"<% if myVar="two" then response.write "selected" end if%>>two</option>
    <option value="three"<% if myVar="three" then response.write "selected" end if%>>three</option>
    </select>
    Oh, and why are you using session variables?
    If it's to save a user's choices, but you only need them in the next/same page like this, then you're making extra work for yourself.
    You only need session variables to save things that a page several clicks away need, or if you want to imitate form persistence.
    Last edited by nikkiH; 09-21-2005 at 10:38 PM.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

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