enable a text field onclick or onchange

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jessy
    New Member
    • Oct 2006
    • 106

    enable a text field onclick or onchange

    I dont know if im postin in the right forum coz im not sure whether this is JS or PHP problem ..
    my problem is i have a text field which is disabled and i need to enable it when the user selects specific option so this should be done through the id of the field but this field is generated in a while loop so only the first text field gets affected by my javascript function ..i know the id should be unique so how shall i implement this :
    here's the code:
    Code:
    function enable()
        {   
           document.getElementById("demo1").disabled=false;  
        }
     while($row=mysql_fetch_array($query))
                       {
                       	         echo" <td> <select name=status onchange=enable()>";?>
                       	         <option <?if($row[order_status]=='pending') echo "selected"?> >pending</option>
                       	          <option <?if($row[order_status]=='shipped') echo "selected"?>>shipped</option>
                       	          </td>
    <td><input type="text" id="demo1" name="date" value="<?echo $arr[0]?>" disabled="disabled"
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    add a number to the id name (e.g. by a count variable).
    [PHP]$count = 0;
    while ([…]) {
    // code
    echo "[…] <input id=\”demo$count \" […]";
    $count++;
    }[/PHP]
    this works for a known amount (1) of fields.

    if you want to activate more than one (or an unknown amount) set a class attribute and check that in your javascript function (be aware that the implementation of getElementsByCl assName() is different between browsers, if at all).

    to write valid HTML code NEVER use duplicate ids (as you see it will sooner or later mess up something)

    regards

    Comment

    • jessy
      New Member
      • Oct 2006
      • 106

      #3
      what u said sounds Great but how can i change that JS line :

      document.getEle mentById("demo< ?=$count?>").di sabled=false;
      its not working !!

      Comment

      • jessy
        New Member
        • Oct 2006
        • 106

        #4
        U know i think i figured it out :)

        but Thanks a Million for your advice and ur great Help



        i love you Bytes

        Comment

        Working...