www.webdeveloper.com
Results 1 to 11 of 11

Thread: Auto selecting item in a drop down list on textbox.text on submit

  1. #1
    Join Date
    Jan 2014
    Posts
    5

    Post Auto selecting item in a drop down list on textbox.text on submit

    hi,

    I am struck with this problem. I have a textbox, submit button and a drop down list populated dynamically from MySQL. Now I require drop down to be automatically select the item which is in textbox. The text in textbox is the result of MySQL query of a database. Can anybody help me.

    venkatesh

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    817
    ??
    Do you mean that when the user puts something into the text box (an <input type='text' ?) you want the screen to automatically change the selected item in the drop down to match it? That's what it sounds like you are saying.

  3. #3
    Join Date
    Jan 2014
    Posts
    5
    Quote Originally Posted by ginerjm View Post
    ??
    Do you mean that when the user puts something into the text box (an <input type='text' ?) you want the screen to automatically change the selected item in the drop down to match it? That's what it sounds like you are saying.

    Hi,

    correct. Actually the textbox is fills the result of a query from database. so my problem on submitting the screen to automatically change the selected item in the drop down to match it and select it. thank u in advance

    venkatesh

  4. #4
    Join Date
    Jan 2014
    Posts
    5
    hi,

    thank u in advance. same thing as u thought. I require the drop down to match and select the item which matches exactly in text box on submit.

    venkatesh

  5. #5
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    817
    a - the user types something into the text box;
    b - your javascript code is supposed(?) to find something in the dropdown items that matches the text that the user just typed in and make that value the selected item in the dropdown
    c - what if it doesn't match?

    Is this an accurate description of what you want?

  6. #6
    Join Date
    Jan 2014
    Posts
    5
    Quote Originally Posted by ginerjm View Post
    a - the user types something into the text box;
    b - your javascript code is supposed(?) to find something in the dropdown items that matches the text that the user just typed in and make that value the selected item in the dropdown
    c - what if it doesn't match?

    Is this an accurate description of what you want?
    hi,

    if it does not match an alert msg - not in the list and select the default item. other things same as u think is correct. thank u for sparing some time with my request in advance

    venkatesh

  7. #7
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    817
    I'm not understanding your answers. Your English is mis-leading.

    Why do you want the user to type in some free-form text and THEN want your javascript to try and guess what item in the dropdown matches it????? Why not have the user select the dropdown? From what you are describing it sounds like you are asking for a user to categorize something and then provide the description of it, in which case you don't need JS to do any selection for you.

  8. #8
    Join Date
    Jan 2014
    Posts
    5
    Quote Originally Posted by ginerjm View Post
    I'm not understanding your answers. Your English is mis-leading.

    Why do you want the user to type in some free-form text and THEN want your javascript to try and guess what item in the dropdown matches it????? Why not have the user select the dropdown? From what you are describing it sounds like you are asking for a user to categorize something and then provide the description of it, in which case you don't need JS to do any selection for you.
    hi, this is my code

    <?php require_once('../Connections/conn.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
    if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
    }

    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

    switch ($theType) {
    case "text":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "long":
    case "int":
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    break;
    case "double":
    $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
    break;
    case "date":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "defined":
    $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
    break;
    }
    return $theValue;
    }
    }

    mysql_select_db($database_conn, $conn);
    $query_rshall = "SELECT bookings_items2.id, bookings_items2.hall FROM bookings_items2 WHERE bookings_items2.`state`=1 ORDER BY bookings_items2.list_order";
    $rshall = mysql_query($query_rshall, $conn) or die(mysql_error());
    $row_rshall = mysql_fetch_assoc($rshall);
    $totalRows_rshall = mysql_num_rows($rshall);
    ?>
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Untitled Document</title>
    </head>

    <body>
    <form name="form1" method="post" action="">
    <label for="textbox"></label>
    <input type="text" name="textbox" id="textbox">
    <input type="submit" name="submit" id="submit" value="Submit">
    <label for="dropdown1"></label>
    <select name="dropdown1" id="dropdown1">
    <?php
    do {
    ?>
    <option value="<?php echo $row_rshall['id']?>"><?php echo $row_rshall['hall']?></option>
    <?php
    } while ($row_rshall = mysql_fetch_assoc($rshall));
    $rows = mysql_num_rows($rshall);
    if($rows > 0) {
    mysql_data_seek($rshall, 0);
    $row_rshall = mysql_fetch_assoc($rshall);
    }
    ?>
    </select>
    </form>
    </body>
    </html>
    <?php
    mysql_free_result($rshall);
    ?>

    The textbox actually populated by a query from a database. On submitting that text, dropdown to select automatically the item . the text in textbox will be in dropdown as the same is dynamically populated from database.
    thanks.

    venkatesh

  9. #9
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    817
    I will not look at your code. It is moronic and out-dated. Why would you check for the existence of a function that you are only going to create with the next lines of code? Who taught you that?

    Also - switch your db interface to mysqlI or pdo, since MySQL_* is deprecated and not to be used.

    And most importantly you have posted this code somewhere previously and been taken to task by others for these same reasons as well as more for the ways you are doing things. If you wrote this code, start again, as I believe you were told.

  10. #10
    Join Date
    Jul 2014
    Posts
    1
    I also want to try and accomplish this ridicules request.

    But my input box will only accept integers and must then select in the drop down according to the number.
    The reason for this is reward/give a user with a percentage (input box) and auto select symbol (drop down). If the percentage is not to the programing rules the user must be able to select a different symbol.

    Not sure how to tackle this but would think doing this with javascript instead of php or combination of both.

    Hope this makes sense.

  11. #11
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    817
    ARE YOU hijacking this post from the OP??? Really??

    1 - start your own post
    2 - Learn how to express yourself in your writing. No - I don't have single clue what you are talking about.
    JG
    PS - If you're posting here you should be using:

    error_reporting(E_ALL | E_NOTICE);
    ini_set('display_errors', '1');


    at the top of ALL php code while you develop it!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles