473,322 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

enable a text field onclick or onchange

106 100+
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:
Expand|Select|Wrap|Line Numbers
  1. function enable()
  2.     {   
  3.        document.getElementById("demo1").disabled=false;  
  4.     }
  5.  while($row=mysql_fetch_array($query))
  6.                    {
  7.                                 echo" <td> <select name=status onchange=enable()>";?>
  8.                                 <option <?if($row[order_status]=='pending') echo "selected"?> >pending</option>
  9.                                  <option <?if($row[order_status]=='shipped') echo "selected"?>>shipped</option>
  10.                                  </td>
  11. <td><input type="text" id="demo1" name="date" value="<?echo $arr[0]?>" disabled="disabled"
Nov 13 '08 #1
3 6685
Dormilich
8,658 Expert Mod 8TB
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 getElementsByClassName() 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
Nov 13 '08 #2
jessy
106 100+
what u said sounds Great but how can i change that JS line :

document.getElementById("demo<?=$count?>").disable d=false;
its not working !!
Nov 13 '08 #3
jessy
106 100+
U know i think i figured it out :)

but Thanks a Million for your advice and ur great Help



i love you Bytes
Nov 13 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: HolaGoogle | last post by:
Hi all, Can you please tell me what's wrong with my code??? i do have this database in wich i have to field.One is a "yes/no" field and another one is "number" field. To display the yes/no field...
2
by: HolaGoogle | last post by:
Can you please tell me the right way to do this?? it's realy important! thanks in advance... Hi all, Can you please tell me what's wrong with my code??? i do have this database in wich i have...
7
by: JW | last post by:
hello everybody I've got the following problem. I'm writing a form and I'm using javascript to validate fields (i.e. numeric, not blank). When my scripts detects an error I want it to put the...
5
by: simon_s_li | last post by:
Hi, I have 5 fields in line where I need to drag and drop the text from one field to another field and then all the fields need to re-order themselves. So for instance if I drag the text in...
18
by: Diogenes | last post by:
Hi All; I, like others, have been frustrated with designing forms that look and flow the same in both IE and Firefox. They simply did not scale the same. I have discovered, to my chagrin,...
1
by: jschlosser | last post by:
I can enable a text box with an onChange if ANY option is selected from a select list, but how do I do this for a specific selection? Even better would be if the field didn't appear until after the...
7
by: kirkgilbert | last post by:
I am trying to do an onchange event in a form using a text field. The form is tied to a record set that is part of a repeated region. One the first record when I edit the data it works perfectly. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.