www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 11-21-2009, 04:32 PM
    Glorifindal Glorifindal is offline
    Registered User
     
    Join Date: Nov 2008
    Posts: 6
    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>
    However, on one page I have multiple forms - taken from the database, displayed as rows - and each row / form should be toggled readonly. At the moment it only works on the first form / first row.

    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
    	}
    ?>
    Can someone suggest how I can get every row / form to work, what am I not doing ?

    Many thanks in advance

    Glorifindal
    Reply With Quote
      #2  
    Old 11-21-2009, 10:02 PM
    crh3675's Avatar
    crh3675 crh3675 is offline
    Web Demystifier
     
    Join Date: Jan 2004
    Location: Washington DC
    Posts: 1,103
    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 ?>" >
    instead and pass the current element.

    Code:
    onclick="toggleWrite(this)"

    Code:
          function toggleWrite(button)
          {
             $('.readonly', button.form).removeAttr('readonly');
          }
    __________________
    Bittersweet web development.
    Reply With Quote
      #3  
    Old 11-22-2009, 03:56 AM
    Glorifindal Glorifindal is offline
    Registered User
     
    Join Date: Nov 2008
    Posts: 6
    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
    Reply With Quote
      #4  
    Old 11-22-2009, 04:32 AM
    Glorifindal Glorifindal is offline
    Registered User
     
    Join Date: Nov 2008
    Posts: 6
    Is it also possible to change the button text / color once it has been clicked - using the same javascript ?
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 03:53 PM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.