Filling a text box when radio button is clicked

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • KDawg44

    Filling a text box when radio button is clicked

    Hi,

    I am writing a PHP website. When I am taking some input from a user,
    I write some static radio buttons for a category, and then also write
    some more that are generated based on a query to a database. I would
    like to have a text box for a description of the category. I would
    like that to be able to be typed in if the user selects on of the
    static options but automatically filled in by data from the database
    if they select one of the radio buttons that are DB generated. I
    would also like to be able to prevent the user from changing the text
    box if it is filled in with DB data (if possible, not that big of a
    deal if too difficult).

    Thanks.

  • KDawg44

    #2
    Re: Filling a text box when radio button is clicked

    On Mar 7, 3:16 pm, "KDawg44" <KDaw...@gmail. comwrote:
    Hi,
    >
    I am writing a PHP website. When I am taking some input from a user,
    I write some static radio buttons for a category, and then also write
    some more that are generated based on a query to a database. I would
    like to have a text box for a description of the category. I would
    like that to be able to be typed in if the user selects on of the
    static options but automatically filled in by data from the database
    if they select one of the radio buttons that are DB generated. I
    would also like to be able to prevent the user from changing the text
    box if it is filled in with DB data (if possible, not that big of a
    deal if too difficult).
    >
    Thanks.

    I see how to set this with JavaScript. Can I pass the results of a
    PHP query into a javascript? Something like this?

    while ($row = mysql_fetch_row ($rs) {
    echo "<input type = radio name = radio1 value = '" . $row[0] . "'
    onclick = 'fillTextBox(" . $row[0] . "," . $row[1] . ")'>";
    }

    and then have a JavaScript function something like:

    function fillTextBox(var cat, var dbData) {
    document.getEle mentById(cat).v alue = dbData;
    }


    THanks.

    Comment

    • Jerry Stuckle

      #3
      Re: Filling a text box when radio button is clicked

      KDawg44 wrote:
      On Mar 7, 3:16 pm, "KDawg44" <KDaw...@gmail. comwrote:
      >Hi,
      >>
      >I am writing a PHP website. When I am taking some input from a user,
      >I write some static radio buttons for a category, and then also write
      >some more that are generated based on a query to a database. I would
      >like to have a text box for a description of the category. I would
      >like that to be able to be typed in if the user selects on of the
      >static options but automatically filled in by data from the database
      >if they select one of the radio buttons that are DB generated. I
      >would also like to be able to prevent the user from changing the text
      >box if it is filled in with DB data (if possible, not that big of a
      >deal if too difficult).
      >>
      >Thanks.
      >
      >
      I see how to set this with JavaScript. Can I pass the results of a
      PHP query into a javascript? Something like this?
      >
      while ($row = mysql_fetch_row ($rs) {
      echo "<input type = radio name = radio1 value = '" . $row[0] . "'
      onclick = 'fillTextBox(" . $row[0] . "," . $row[1] . ")'>";
      }
      >
      and then have a JavaScript function something like:
      >
      function fillTextBox(var cat, var dbData) {
      document.getEle mentById(cat).v alue = dbData;
      }
      >
      >
      THanks.
      >
      Yep, you'll need to use javascript for anything happening client-side.

      And sure - it doesn't matter how the JS is generated - from a page or
      echoed from PHP, for instance. The browser has no idea.

      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      Working...