www.webdeveloper.com
Results 1 to 8 of 8

Thread: Change Texbox when change ComboBox

Hybrid View

  1. #1
    Join Date
    Nov 2012
    Posts
    13

    Change Texbox when change ComboBox

    I have a php page that include a ComboBox and a TextBox, I need the TextBox change his value automatically depending on the value selected in the ComboBox.

    I have tried with onchange event but I can't pass values between javascript and PHP.

    Can anyone help me please?

    Thanks in advance

  2. #2
    Join Date
    Feb 2012
    Location
    youTUBE
    Posts
    234
    You need the textbox to change its value depending on a combo box selection. This must mean there is an onto mapping between Cbox values and Tbox values. Further it seems as if this mapping resides on the server side, as I can gather from your description of the problem.

    In this scenerio the easiest way is, to do a quick Ajax call to the server with the new Cbox value when it changed, and fill the Tbox with its corresponding value on the Ajax reply.

    Otherwise you will have to send the relational values and store them in a Javascript array making them accessible at the Client/Browser side, when the onChange for the Cbox is triggered.

    I can lend you some code to do it, if you are stuck in syntatic overload.
    Knowledge is that which can be shown to be the case, and Intelligence is the method one uses to deploy the demonstration of what is the case, everything else is Information.

    For a stronger Text reading try:
    http://www.wyc3.com/diction.php

  3. #3
    Join Date
    Nov 2012
    Posts
    13
    Please, could you give the code to solve this problem?

    Thanks

  4. #4
    Join Date
    Feb 2012
    Location
    youTUBE
    Posts
    234
    Ok, I will show you the code, but it will have to be done in steps.

    (1) You will need the Ajax support routines that I can provide.
    (2) The Server request handler will be filled in by you, using a sort of prototype I can outline.
    (3) The HTML support with element ID's is on your page and plate.

    How it will work.
    (A) When the onChange for the Combo box triggers, it will call a Javascript function that will prepare an Ajax call to a specific ServerRequestHandler sitting on your Website - RequestText.php.
    (B) When the request returns to the Browser, a Javascript function will unwrap the answer and place it into the Text Box.

    When you are ready to continue let me know.
    Knowledge is that which can be shown to be the case, and Intelligence is the method one uses to deploy the demonstration of what is the case, everything else is Information.

    For a stronger Text reading try:
    http://www.wyc3.com/diction.php

  5. #5
    Join Date
    Nov 2012
    Posts
    13
    WyCnet thanks for response... I do not have enough knowledge right now to understand what you say to me, If you agree, let's look the simplest example

    A php page:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Documento sin título</title>
    </head>

    <body>
    <select name="milista" id="milista">
    <option value="1">FORD</option>
    <option value="2">AUDI</option>
    <option value="3">BMW</option>
    <option value="4">PORSCHE</option>
    </select>
    <label for="MicampoTXTO"></label>
    <input type="text" name="MicampoTXTO" id="MicampoTXTO" />
    </body>
    </html>


    When user select a car company I need the name of the company passes to TextBox.. ¿How can i do it?

    Thanks very much.

  6. #6
    Join Date
    Feb 2012
    Location
    youTUBE
    Posts
    234
    The script to run it.
    Code:
    <script type="text/javascript">
    var carMAP = ['none','Ford Mptor Company','Audi','Bmw','Porsche'] ;
    function inTEXTbox(cVAL) { if (cVAL==0) return ;
    var txt = document.getElementById("MicampoTXTO") ;
    txt.value = carMAP[cVAL] ;
    }
    </script>
    The options to complete it.

    Code:
    <select name="milista" id="milista" onchange="inTEXTbox(this.value)">
    <option value="0">Select a Car</option>
    <option value="1">FORD</option>
    <option value="2">AUDI</option>
    <option value="3">BMW</option>
    <option value="4">PORSCHE</option>
    </select>
    until next time...
    Knowledge is that which can be shown to be the case, and Intelligence is the method one uses to deploy the demonstration of what is the case, everything else is Information.

    For a stronger Text reading try:
    http://www.wyc3.com/diction.php

  7. #7
    Join Date
    Nov 2012
    Posts
    13
    Fantastic!! Code works perfectly...
    Now if you were so kind, I would appreciate it if you could show me how to do it when the combo is filled with data from a database. The table is simple, it has two fields: code of country (P_codprocedencia) and Name of country (P_procedencia):

    <?php require_once('Connections/mi.php'); ?>
    <?php
    mysql_select_db($database_mi, $mi);
    $query_RecordsetCountries = "SELECT * FROM procedencias";
    $RecordsetCountries = mysql_query($query_RecordsetCountries, $mi) or die(mysql_error());
    $row_RecordsetCountries = mysql_fetch_assoc($RecordsetCountries);
    $totalRows_RecordsetCountries = mysql_num_rows($RecordsetCountries);
    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Documento sin título</title>
    </head>

    <body>
    <label for="ListCountries"></label>
    <select name="ListCountries" id="ListCountries">
    <?php
    do {
    ?>
    <option value="<?php echo $row_RecordsetCountries['P_codprocedencia']?>"><?php echo $row_RecordsetCountries['P_procedencia']?></option>
    <?php
    } while ($row_RecordsetCountries = mysql_fetch_assoc($RecordsetCountries));
    $rows = mysql_num_rows($RecordsetCountries);
    if($rows > 0) {
    mysql_data_seek($RecordsetCountries, 0);
    $row_RecordsetCountries = mysql_fetch_assoc($RecordsetCountries);
    }
    ?>
    </select>
    <label for="CountryTextBox"></label>
    <input type="text" name="CountryTextBox" id="CountryTextBox" />
    </body>
    </html>
    <?php
    mysql_free_result($RecordsetCountries);
    ?>




    THANKS!!

  8. #8
    Join Date
    Feb 2012
    Location
    youTUBE
    Posts
    234
    You can generate the javascriot array the same way you are generating the options.
    var carMAP = [] ;
    carMAP['P_codprocedencia'] = 'P_procedencia';
    but you will use the correct syntax.

    I do not program Php the way you have listed it, therefore I could not provide similar type coding.
    Knowledge is that which can be shown to be the case, and Intelligence is the method one uses to deploy the demonstration of what is the case, everything else is Information.

    For a stronger Text reading try:
    http://www.wyc3.com/diction.php

Thread Information

Users Browsing this Thread

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

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