Brion
Brion

Reputation: 3

How to disable text field or input if a value is present?

I am trying to pull the value(which works) and disable the field from input(which will NOT work) and post it. Thanks in advance.

Here is my code below:

<textarea name="title" id="title"><?php
    $query  = "SELECT * FROM table WHERE id = '$member'";
    $result = mysql_query($query);
    $member = mysql_real_escape_string($member);

  while($row = mysql_fetch_array($result)) {
    $title = $row['title'];
    echo $title;
    }?> <?=($disable ? " disabled=\"disabled\"" : "");?>
    <?php if($title == true) {
    $disable = true;
    }
    else {
    $disable = false;
    }
    ?></textarea>

Upvotes: 0

Views: 4947

Answers (1)

Demian Brecht
Demian Brecht

Reputation: 21368

I'm not sure if you're trying to disable it based on query results (which it looks like what you're trying to do). You're closing the textarea opening tag before setting the disabled attribute. The disabled attribute has to be an attribute of the textarea tag:

<textarea disabled="disabled"></textarea>

Upvotes: 2

Related Questions