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
    Nov 2004
    Posts
    95
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with selecting strings in a select field...

    For example if the user selected New York and pressed the submit button php will do some checking and if an error came up it will hault and echo out the errors and keep the orginal information in the fields. I need to do this with a select field. I would like to use javascript because i think it would be easier then pulling info out of a database and outputting it. I already have a select field with the information and i just need it to select previous information. Except i have no clue how to code in javascript. Could anyone help me out?

    Thanks,
    Rich

  • #2
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Could you elaborate?

    What are these errors you are reffering to? At what point do you wish to revert to the prior selection. . .since js is clientside, and any function that would be run to check for these errors would already be loaded with the page, the selected option should already be retained. Your needs just really aren't clear.

    Basscyst
    Last edited by Basscyst; 01-20-2005 at 11:11 PM.
    Helping to build a bigger box. - Adam Matthews

  • #3
    New Coder
    Join Date
    Nov 2004
    Posts
    95
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Basscyst
    Could you elaborate?

    What are these errors you are reffering to? At what point do you wish to revert to the prior selection. . .since js is clientside, and any function that would be run to check for these errors would already be loaded with the page, the selected option should already be retained. Your needs just really aren't clear.

    Basscyst

    Sorry for not elaborating better. I was in a rush when i posted before cause i had to get to work. Anyways, What i need to do is select the previous selection in the select field. Say the user selected New York and they hit the submit button I need something to automatically select New York or any other state when the form comes up again. Is this possible to do with Javascript?

    Here's what i thought on how to do this: First when the page is submitted have javascript set a cookie with the value of the select field. Next when the page loads use javascript to read the cookie and have javascript automatically find and select that value in the select field. Just I have no clue where to get started with javascript.

    -peace,
    Rich
    Last edited by dottedquad; 01-21-2005 at 03:06 AM.

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Could be done using cookies, but you may consider that some users might restrict the cookies receiving, thus the best way is a server-side method.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    New Coder
    Join Date
    Nov 2004
    Posts
    95
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Kor
    Could be done using cookies, but you may consider that some users might restrict the cookies receiving, thus the best way is a server-side method.
    Alright well i did it an easier way:

    function getstate() {
    document.accounts.states.selectedIndex = <?php echo $_POST['states']; ?>;
    }

    <body onload="getstate()">

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Well yea... this is a server-side method, as I have suggested...
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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