...

View Full Version : List box to textbox



dips_007
03-22-2004, 11:36 PM
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>

kwhubby
03-23-2004, 12:19 AM
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)
}
}

dips_007
03-23-2004, 12:39 AM
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>

kwhubby
03-23-2004, 12:51 AM
Ah woops sorry :o 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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum