Hi.

How could we unlock the locked textbox whenever users click a button -say ' customise button'.
Then users are able to customise the boxes and save it as a set of new data with new ID?

Help is much appreciated.

Recommended Answers

All 20 Replies

hi
sorry but what you want...
if you want that somebody clicks on button that time textbox enable so you can call javascrit function on button click event
As i posted one example here

<input type="text" disabled="disabled" name="txt1"/>
<input type="button" value="Click me" onblur="func_unlock();">
<script type="text/javascript">
function func_unlock()
{
	document.getElementByid('txt1').disabled=false;
}
</script>

Thanks

<input type="text" disabled="disabled" name="txt1"/>
<input type="button" value="Click me" [B]onblur[/B]="func_unlock();">
<script type="text/javascript">
function func_unlock()
{
	document.getElementByid('txt1').disabled=false;
}
</script>

Are you sure you don't mean onclick ?
That wouldn't fire when the button was clicked, but rather when the button is deselected.

Edit:
And you misuse the name attribute.
Only IE incorrectly fetches tags via the document.getElementById function based on their name attribute.
You should use the id attribute if your intend to fetch the element using that function.

Like:

<html>
    <head>
        <title>JS Click Test</title>
        <script type="text/javascript">
        function EnableBox() {
            var box = document.getElementById('disabledBox');
            box.value = "";
            box.disabled = false;
            box.focus();
        }
        </script>
    </head>
    <body>
        <input id="disabledBox" type="text" disabled="disabled" value="I'm disabled" />
        <button onclick="javascript: EnableBox();">Enable</button>
    </body>
</html>

hi
sorry atil ....
i post onblur() event here it's my mistake
thanks for that

Thanks Tulsa & Atil,
but as far I understand the example you gave is for a specific / one textbox.. Am I right?
What I intend to do is..
1- by clicking 1 button-"customise"..all textboxes will we unlocked
2- and we can update/edit the data in it..
3- subsequently save the data as a new set of data in a database.

I used to do it in VB but as I am a php newbie.. I don't have any ide of it.

Thanks in advanced

>Thanks Tulsa & Atil,
but as far I understand the example you gave is for a specific / one textbox.. Am I right?
What I intend to do is..

What are you doing? Tulsa & Atil explained how to enabled or disabled an item? Is there any problem to write a code for another textbox?

Thanks Tulsa & Atil,
but as far I understand the example you gave is for a specific / one textbox.. Am I right?
What I intend to do is..
1-

by clicking 1 button-"customise"..all textboxes will we unlocked

is it possible to do this in Php? If not..it is ok..I might change my idea..edit the boxes individually & finally save it as a new set of data.

2- and we can update/edit the data in it..

3- subsequently save the data as a new set of data in a database.

Just insert [INSERT INTO] new data in databse, isn't it?
BUt How to update/increase the ID automatically in MySQL database. Logically ID+1, but I do not know the syntax.

Thanks in advanced

Thank you

Let's see your code.

Let's see your code.

ok..thanks.this is my code

<?php
   $query= mysql_query(" SELECT * FROM lesson
   					WHERE lessonID='" . $_GET['lessonID'] . "'");
   
      while($entry=mysql_fetch_array($query))
      {
	 echo " Subject: ";
	 echo '<input  name="subject" readonly="readonly" value="', $entry['subject'] , '" /><br />';
         echo " Year:"; 
	 echo '<input  name="year" readonly="readonly" value="', $entry['year'] , '" /><br />';
	 
    
  }

   ?>

If you want JavaScript to enable multiple boxes with one button click, you need to either statically fetch them all (like my example did, but with more than one box), or create a script to fetch all of the boxes you want.

The document.getElementsByTagName could fetch all the input elements for you so you could sort through them and find those you need to enable.

var boxes = document.getElementsByTagName('input');
for(var i = 0; i < boxes.length; i++) {
  // Sort through the boxes here.
}

You could give all the boxes that you need to enable a specific attribute to check, like 'doEnable', which you could fetch in your JavaScript code with the getAttribute function.
Like:

<input doEnable="yes" .../>
if(boxes[i].getAttribute('doEnable') == 'yes') {
  boxes[i].disabled = false;
}

And P.S.
If you want to send multiple <input> boxes with the same name to PHP, they should be named <input name="name[]" .../> . That way all of them will be sent to PHP as an array, not just the last one in the form.

ok..thanks.this is my code

<?php
   $query= mysql_query(" SELECT * FROM lesson
   					WHERE lessonID='" . $_GET['lessonID'] . "'");
   
      while($entry=mysql_fetch_array($query))
      {
	 echo " Subject: ";
	 echo '<input  name="subject" readonly="readonly" value="', $entry['subject'] , '" /><br />';
         echo " Year:"; 
	 echo '<input  name="year" readonly="readonly" value="', $entry['year'] , '" /><br />';
	 
    
  }

   ?>

Your code misses :

1. Form tag
2. Single quote never evaluates/expand variables.
3. No submit buttons.

Get a hint from the given code:

page1.php

<?php
   $flag="disabled=\"disabled\"";
   $cmd=$_REQUEST["cmd"];

    $query= mysql_query(" SELECT * FROM lesson
   			 WHERE lessonID='" . $_GET['lessonID'] . "'");
   
   $no="";
   $name=""; 
    if($entry=mysql_fetch_array($query)) {
         $no=$entry[0];  $name=$entry[1];
     }

   if(isset($cmd)) {
      if($cmd=="Edit") 
           $flag="";
     else
     if($cmd=="Update") {
             ..... Write code to update a record.
        }
     }
?>

<form method="post" action="page1.php">
No <input type="text"  
             <?php echo $flag ?> 
             name="no" 
             value="<?php echo $no?>"
              />
<br/>
Name <input type="text"  
              <?php echo $flag ?> 
              name="name" 
              value="<?php echo $name?>"
               />
  
<input type="submit" name="cmd" value="Edit"/>
<input type="submit" name="cmd" value="Cancel"/>
<input type="submit" name="cmd"  <?php echo $flag ?>   value="Update"/>
</form>

Thanks Atli & Adatapost for your responses.

Adatapost,
What I intend to do is to insert a new record after customising the display data ( by click edit button).. so, I need to change "update" to "insert"..am I?

& how can the id be increased based on the highest id in the table?

thanks

Thanks Atli & Adatapost for your responses.

Adatapost,
What I intend to do is to insert a new record after customising the display data ( by click edit button).. so, I need to change "update" to "insert"..am I?

& how can the id be increased based on the highest id in the table?

thanks

Add another submit button with value="Insert" and name="cmd". Compare value of $cmd and if it is "Insert" then write code to insert a record.

hello all,
thanks for your input

& how can the id be increased based on the highest id in the table?

what I mean here is to enable an ID auto increment whenever we insert a new record to the table.
Do I have to query the maximum number in that table,
then ID++.
Is it correct? any proper syntax?
thanks

You can simply add the AUTO_INREMENT option to the column that is supposed to incremented, and leave it out of the INSERT query.

CREATE TABLE test (
  `id` Int Unsigned Not Null Auto_Increment,
  `value` VarChar(255) Not Null,
  Primary Key(`id`);
);

INSERT INTO test(`value`)
VALUES ('First'), ('Second'), ('Third');

SELECT * FROM test;
+----+--------+
| id | value  |
+----+--------+
|  1 | First  |
|  2 | Second |
|  3 | Third  |
+----+--------+

owh..thanks
I did used AUTO incerement.
tq.

HI adatapost,
I am sorry for coming to this thread again
several questions to ask:

$flag="disabled=\"disabled\"";

to enable the textboxes after click edit, can we code like this ?

$unflag="enabled=\"enabled\"";

I have tried this but it doesn't work.

when click the EDIT button, the value in textbox
remains..& can be editted.
currently the value is set to empty = $flag="";

thank you

$flag="";

There is no enabled attribute. There is no need for it.
If the tag isn't specifically marked as disabled, it will be enabled.
So to enable it, simply remove the disabled attribute, as adatapost demonstrated.

If the tag isn't specifically marked as disabled, it will be enabled.
So to enable it, simply remove the disabled attribute, as adatapost demonstrated

ic, ok..thanks:$
but I would like to retain the value that is currently displayed.
by using this

$flag="";

the textbox is enable..it's correct..but the value inside is emptied.

thank you

thanks all..
I have succesfully customised the textboxes,
however when I try to save it as a set of new record..
nothing happened to the database.
no record is added.

As suggested before..I used INSERT INTO..

if(isset($cmd)) {
	  if($cmd=="Save") {
  			
 		 mysql_query("INSERT INTO lesson VALUES subject='$subject', year='$year', learningArea='$learningArea' , objectives='$objectives',  ability='$ability' 
		  where lessonID='$lessonID'");
      			}
				}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.