Results 1 to 5 of 5

Thread: javascript one

  1. #1

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Question javascript one

    1) Page1.htm - contains only a submit button control.
    2) User clicks this & sends page1 to Page2.asp
    3) Page3.asp contains <select> and hidden field.
    4) User selects from the combobox.
    5) This selection text is placed into the hidden field.
    6) The page then is then automatically submitted - to itself.

    4-6 keep going in a loop, every time the user chooses an entry, the page reloads. Now when the page loads, the combobox shows the default first entry. What I'd like is for this to show trhe last selected entry.

    What I've done is set up a body_onload event which loops through all the entries in the combobox and selects the one which matches the request pages hidden text field's text:
    Code:
    function SelectChosenGam() {
    	if (request.form("hidChosen") != "") {
    		var intCounter;
    		
    		for(intCounter=0; intCounter<theForm.combo1.options.length; intCounter++) {
    			if (theForm.combo1.options[intCounter] == Request.Form("hidChosen")) {
    				theForm.combo1.selectedIndex = intCounter;
    			}
    		}
    	}
    }
    This works fine when the page2.asp page is submitting to itself. But then I realised that page1.htm submits to this page also & doesn't have the hidden field. How can I trap for this please ?
    Last edited by alex_read; Nov 20th, 2001 at 04:57 AM.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  2. #2
    Hyperactive Member progressive's Avatar
    Join Date
    Sep 2001
    Location
    Manchester, UK
    Posts
    404
    I couldn't make head nor tail of that!

    Heres how I'd do it

    <select name="select">
    <option value="one" selected>one</option>
    <optionvalue ="two" >two</option>
    </select>

    the above shows option one selected!

    Use asp to write out the combo box!
    and put a variable inplace of the selected
    eg

    dim one as string

    print '<option value="one"' & one & '>one</option>

    so all you do now is test what you got for your input, if you got a one then simply do

    one = "selected"
    print '<option value="one"' & one & '>one</option>

    I'm not familiar with ASP so I don't know the syntax, but this is an adapted method of one I use for Perl!

    If you need a more detailed explanation you'll have to wait until tommorow!!

  3. #3

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Hi Progressive - thanks for that. You're right, I didn't explain that one too well, so had another attempt.

    Please look again at the above as I've changed the wording of the question. It fails on the first if (request.form("hidChosen") != "") { line as it can't find the hidChosen field of page1.

    Thanks !

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  4. #4
    Hyperactive Member progressive's Avatar
    Join Date
    Sep 2001
    Location
    Manchester, UK
    Posts
    404
    try this

    Code:
    onload="setTimeout('SelectChosenGam()', 1000)"
    The onload event is not a particulary good method, when you are referencing form elements, and layers. As when the onload event fires these elements have not always been set!

    This may be what is causing you problems!

    Let me know how you get on!

  5. #5

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    I've stuck a hidden field in the page1.htm - this on'es been bugging me so though not too professional, I thought sod it !

    Thanks for the suggestions

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

Posting Permissions

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



Click Here to Expand Forum to Full Width