0

I am coding in PHP. I have a table containing 'x' number of Textboxes. 'x' varies.

I want the textboxes initially readOnly. But when I click on a textbox, it should be editable.

I can write the code for fixed number of textboxes. But I want to know how it is done for variabe number.

My sample code:

<form>
<?php 
for($i=0;$i<$x;$i++)
{
   echo("<input name='fe_text[]' type='text' readonly /><br/>");
}
 ?>
<input type="submit" value="submit"/>
</form>
  • 5
    Why make them read-only when you intend to make them editable anyway? I don't get your logic. – Madara's Ghost Jun 03 '13 at 20:04
  • 2
    I don't understand why, but add ` onclick="this.readOnly=false;"` to the ` – David Starkey Jun 03 '13 at 20:09
  • You could just style the textboxes to look readonly. – Orangepill Jun 03 '13 at 20:19
  • Use jQuery, to toggle the readonly on/off http://stackoverflow.com/questions/1306708/add-readonly-to-input-jquery – on_ Jun 03 '13 at 20:27
  • What problem is it that you're trying to solve; as Madara implies: this makes no sense. *Why* do they need to be `readonly` until someone clicks them? Please, read the following: '[what is the XY problem?](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)' for reference. – David Thomas Jun 03 '13 at 21:17

2 Answers2

0

try this

$('body').on('click', 'input[type=text]', function(){
    $(this).removeAttr('readonly');
});
Bilal Murtaza
  • 785
  • 4
  • 9
0

Just a little trickery with onclick event:

echo("<input name='fe_text[]' type='text' readonly onclick="this.readOnly=false" /><br/>");

or you can use jQuery events

$('#input-container').on('click', 'input' function()
{
   $(this).prop('readonly', false);
});
Richard Nagy
  • 141
  • 9