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 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2004
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    List box to textbox

    Hi this code get the data from a list box into text box 1 how would i get it to check if a text box has data in it , if so put the data in to text box 2 and if thats has data then put the data in to text box 3 if that has data in it then message box.
    I need to make sure if textbox 1 has data and text box 3 has data then data goes in to textbox 2

    town1 = text box
    town2= text box
    town3= text box
    country - list box



    <script language="JavaScript" type="text/JavaScript">

    function AddTown()
    {
    var theForm = document.forms["form1"];
    theForm.town1.value = theForm.country.options[theForm.country.options.selectedIndex].value;
    }
    </script>

  • #2
    Regular Coder
    Join Date
    Nov 2002
    Location
    Carmel California
    Posts
    471
    Thanks
    0
    Thanked 1 Time in 1 Post
    If I am understanding this right, you want the selection made in "country" to go to the first empty text input, and if all are filled then have it alert. If so then you could do it this way:


    function AddTown() {
    var theForm = document.forms["form1"];
    var sdata = theForm.country.options[theForm.country.options.selectedIndex].value;
    if (theForm.town1.value != "") {
    theForm.town1.value = sdata
    }
    else if (theForm.town2.value != "") {
    theForm.town2.value = sdata
    }
    else if (theForm.town3.value != "") {
    theForm.town3.value = sdata
    }
    else {
    alert(sdata)
    }
    }
    Kris Hubby
    kwhubby site

  • #3
    New Coder
    Join Date
    Feb 2004
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Did not work it keeps putting up the message box

    <script language="JavaScript" type="text/JavaScript">

    function AddTown()
    {
    var theForm = document.forms["form1"];
    var sdata = theForm.country.options[theForm.country.options.selectedIndex].value;
    if (theForm.town1.value != "")
    {
    theForm.town1.value = sdata
    }
    else if (theForm.town2.value != "")
    {
    theForm.town2.value = sdata
    }
    else if (theForm.town3.value != "")
    {
    theForm.town3.value = sdata
    }
    else
    {
    alert(sdata)
    }
    }

    </script>

  • #4
    Regular Coder
    Join Date
    Nov 2002
    Location
    Carmel California
    Posts
    471
    Thanks
    0
    Thanked 1 Time in 1 Post
    Ah woops sorry lol, it should be
    function AddTown() {
    var theForm = document.forms["form1"];
    var sdata = theForm.country.options[theForm.country.options.selectedIndex].value;
    if (theForm.town1.value == "") {
    theForm.town1.value = sdata
    }
    else if (theForm.town2.value == "") {
    theForm.town2.value = sdata
    }
    else if (theForm.town3.value == "") {
    theForm.town3.value = sdata
    }
    else {
    alert(sdata)
    }
    }


    sorry I wasn't thinking right when I posted
    Kris Hubby
    kwhubby site


  •  

    Posting Permissions

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