Jump to content

Change "readonly" value on link click


dmhall0

Recommended Posts

I have a standard html form that displays numeric values for 8 different fields.  These increase based on other information and are typically marked as "readonly".

I want to add a RESET link next to each field that allows the user to set these back to 0 (zero); then I have php UPDATE code already completed that updates the database.

 

I assume I need a javascript function that does this, but my knowledge in this area is pretty much NULL.

 

<a onclick="jsfunction" href="javascript:void(0);">Reset Value</a>

 

Help with the function would be GREAT!

Thanks

Link to comment
Share on other sites


<script type="text/javascript">
<!--
window.addEventListener('load', function() {
   var anchors = document.getElementsByTagName('a');
   for( var k in anchors )
   {
      if ( anchors[k].className.substring(0,5).toLowerCase() == 'reset' )
      {
         anchors[k].addEventListener('click', function() {
	    
            document.getElementById(this.className.substring(5).toLowerCase()).value = 0;
         });
      }
   }
});
//-->
</script>
<input type="text" name="test" id="test" value="4" disabled="disabled" ><a href="javascript:void(0);" class="resetTest" >Clear</a>

Link to comment
Share on other sites

Did you change the link's class to reset followed by the ID of the input you want it to change?

 

 

E.g.

 

 

Say your input has an id of  numberofapples (id="numberofapples") the link should have a class of resetnumberofapples (class="resetnumberofapples"), class is case insensitive, but ID MUST BE LOWER CASE.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.