Link to home
Start Free TrialLog in
Avatar of rockas1982
rockas1982Flag for United States of America

asked on

html form text boxes

I hve a form with 2 text boxes

and i have a table in mysql with 3 columns

"from" "to" "area"
10      20     new york
21      30     Vegas
31      40     Philadelphia

i want when someone is typing on the first box something like 15 on the second box to show "new york"  or when he types 33 to show Philadelphia

Any idea ?
Avatar of guvera
guvera
Flag of India image

Avatar of rockas1982

ASKER

not even close autosuggestion interact with one box i want when someone is typing on the first box to check if the number he typed is bigger the from or smaller than to and then display the city name to another box
do you want to go server side to check if number is in between the specified range?
i dont care about that it could be on a array or anything it helps for fast solution the table has 200 rows if it matters

sory for my english
$(document).ready(function() {  

$("#val").keyup(function ()
{

	$.ajax({
		 type: 'GET',
		 url:  "ex.jsp?range="+$("#val").val()),
		 success: function(msg){ 		 
			 $("#state").val(msg);
		}   
	});

     }); 
	 
	


 }); 

Open in new window

<input type='text' value='12' id='val'>
<input type='text'  id='state'>
I have something like this now can you help me fix it search inside an dimensional array or mysql instead of showing the same number

<html>
<head>
<script type="text/javascript">
function changetext(){
	var userInput = document.getElementById('phone').value;
	document.getElementById('area').value = userInput;
}
</script>
<input type='text' onKeyup='changetext()' id='phone' value='' />
<br>
<input type='text' id='area' value='' />

</body>
</html> 

Open in new window

$("#phone").keyup(function ()
{

      $.ajax({
             type: 'GET',
             url:  "ex.jsp?range="+$("#val").val()),
             success: function(msg){              
                   $("#area").val(msg);
            }  
      });

     });

check this.

http://www.roseindia.net/answers/viewqa/Ajax/12186-Auto-Complete-Text-Box---JSP-Servlet.html

ASKER CERTIFIED SOLUTION
Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
IT WORKS ... YOU ARE THE BEST

one small fix

  } else {
   retval = ' ';
    break;

one last question. i have this table in a csv or mysql how can i add them to the array with php or javascript
if you are generating the page using php it is easy.

just pull the values fron the DB into a PHP array and generate the
javascript with a for loop

<?php
echo '<script> numbers = new Array ();';
for ($i = 0; $i<count($yourarray); $i)
{
  echo 'numbers[' . $i . '] ="' . $yourarray[$i] .";'
}
?>

Open in new window



or something like that (my php is a little rusty)
IT WORKS
Any idea what i'm doing wrong here ?

<?php
$result = mysql_query("select * from sites", $con);
$row = mysql_fetch_array($result);

echo '<script> numbers = new Array ();';
for ($i = 0; $i<count($row); $i)
{
  echo 'numbers[' . $i . '] ="' . $row[$i] .";'
}
?>

function showCity(x)
{
retval = ' ';
for (i=0; i<numbers.length; i++)
{
  locvar=numbers[i].split(",");
  if (locvar[0] <= x && locvar[1] >= x)
  {
    retval=locvar[2];
    break;
  } 
}
document.forms.boost.fsite.value = retval;
}
</script>

Open in new window

what result are getting that is wrong?

I notice you are selecting all columns from the sql table.  Does it contain just the three columns you need?

If not you will have to change the select