Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2005
    Thanked 0 Times in 0 Posts

    Question Form auto populate 2nd hidden field

    Please be kind its my 1st real post!!!!

    Im trying to get a form to post to a php page it is all working but i need it to be easier


    <select style="width:100;font-weight : bold" name="city1" tabindex=14>
    <option value="Portsmouth">Portsmouth</option>
    <option value="Poole">Poole</option>
    <option value="Cherbourg">Cherbourg</option>
    <select style="width:100;font-weight : bold" name="countryArr"tabindex=8>
    <option value="GBR">UK</option>
    <option value="FRA">FRANCE</option>

    but i want it to be just one dropdown eg if you select poole or portsmouth it will automaticly select uk but if you select Cherbourg it will select france and the 2nd dropdown is hidden

    any ideas???

  • #2
    New Coder
    Join Date
    Jul 2005
    Thanked 0 Times in 0 Posts

    Created a function to split the value of the input (which seperates the country and city names with the "|" character. If the input has no value it skips the function ... if the input has a value it splits the value and shows both seperate values as an alert. This should be straightforward to save directly to hidden form boxes.

    Hope this helps !

    function auto(val){
    var string = new Array();
    var country;
    var city;
    if(val != ""){
    string = val.split("|");
    country = string[0]
    city = string[1]
    // I've used an alert here but you could just as easily write to 2 different
    // hidden input boxes
    alert("The country is: " + country + "\nThe city is " + city)

    <select onChange="auto(this.value)">
    <option value=""> Select One </option>
    <option value="uk|portsmouth">Portsmouth</option>
    <option value="USA|chicago">chicago</option>


    Posting Permissions

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