|
|||||||
| JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...) |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Toggle attributes on multiple forms
Hi there,
I use the code below to remove the readonly attribute on form elements. Code:
<script type="text/javascript">
function toggleWrite()
{
$("#Housewives").removeAttr('readonly');
$("#Students").removeAttr('readonly');
}
</script>
Each form has an unique id - created so : Code:
while($row = mysql_fetch_array($result))
{
$id = (isset($row['ID']))? $row['ID'] : "";
$formID = "paymentForm".$id;
?>
<fieldset>
<form id="<?php echo $formID; ?>" method="post" action="help.php">
<input type="text" readonly id="Housewives" value="<?php echo $Housewives ?>" >
<input type="text" readonly id="Students" value="<?php echo $Students ?>" >
<input id="payment" type="button" value=" Edit " onclick="toggleWrite()">
</form>
</fieldset>
<?php
}
?>
Many thanks in advance Glorifindal |
|
#2
|
||||
|
||||
|
An ID cannot be reassigned, (http://www.w3.org/TR/xhtml1/). Try using a class
Code:
<input type="text" readonly="readonly" class="readonly" value="<?php echo $Housewives ?>" > Code:
onclick="toggleWrite(this)" Code:
function toggleWrite(button)
{
$('.readonly', button.form).removeAttr('readonly');
}
__________________
Bittersweet web development. |
|
#3
|
|||
|
|||
|
Toggle attributes on multiple forms
Hi there,
many thanks for the speedy reply It works wonderfully - and taught me a great lesson in using (this) MANY THANKS INDEED Glorifindal |
|
#4
|
|||
|
|||
|
Is it also possible to change the button text / color once it has been clicked - using the same javascript ?
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|