rockas1982
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 ?
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 ?
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?
ASKER
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
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);
}
});
});
});
<input type='text' value='12' id='val'>
<input type='text' id='state'>
<input type='text' id='state'>
ASKER
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>
$("#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
{
$.ajax({
type: 'GET',
url: "ex.jsp?range="+$("#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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
or something like that (my php is a little rusty)
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] .";'
}
?>
or something like that (my php is a little rusty)
ASKER
IT WORKS
ASKER
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>
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
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
For this scenario, the best approach is to go for "AutoSuggestTextBox".
Please find the below link for your reference.
http://www.codeproject.com/KB/ajax/AJAXAutoSuggest.aspx
http://www.chrismanciero.com/autosuggest.aspx
http://www.javascriptsearch.com/tutorials/Advanced/tutorials/AUTOSUGGEST2-4.html
http://www.javascriptsearch.com/tutorials/Advanced/tutorials/AUTOSUGGEST2-4.html
http://javascript-reference.info/creating-an-autosuggest-textbox-with-javascript-part-1-4.htm
Hope it may helpful to you.
Regards
Guvera