Results 1 to 4 of 4

Thread: Changing state field if there is choosen country USA?

  1. #1
    Join Date
    Jan 2006
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Changing state field if there is choosen country USA?

    I have seen in web sites that on registration page there is no state but if there is selected country USA it will refresh page and show field with list boy states. Do you know how to do it with function? Need help

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    This isn't PHP.

    It's javascript.

    Something like:

    (This code is likely/probably wrong, but it gives you the idea... it may also need to be customized more to your page.)

    <select onChange="if (this.value == 'USA') visibility.state = 'visible';">
    ....options....
    <option value="USA">USA</option>
    </select>
    <input type="text" id="state" style="visibility:hidden">

    something like that.

    Basically, when the select menu changes, the "visibility:hidden" of the state input (use a select if you want... whatever) is set to visible, so it's then shown.

    (You should also add else visibility='hidden', so it goes away if it was changed)


    again, just outline o fthe code, look up the syntax...
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Although what djr33 stated above is true, this could be pulled off using PHP; however javascript would be the best method of doing this. Being that you would not need to send data to the server, and have the user wait while the page reloads and whatnot, you could simply do this all on the client side.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    No. PHP could NOT do this.

    Yes, it could check that, but it would require, as you said, the page reloading, which would defeat the point, really.

    The only time PHP could be used for this is in a multi-page form, where, for example, each page had one field and it kept going, like a test, or survey or something.

    But javascript is the way to make this happen live.

    Also, I think the better way to do it is this--
    1. use <body onLoad="..."> to set the field(s) to visibility of hidden (I'm not sure if that's fieldname.visibility or fieldname.style, or something else... look it up).
    2. use onChange in the select menu(s)/etc. to check if it's NOT equal to "USA"/etc. and set it to hidden. Otherwise, set it to visible.
    3. Don't, in the html code, use style="visibility:hidden".

    Reason:
    If javascript isn't enabled, it would show up. Otherwise, the user would never be able to access the field.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

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