Jump to content

HTML Basic help


Recommended Posts

I'd use an onChange (so it works for keyboard navigation as well)

 

Errr this might work:

<input type="checkbox" onchange="removeRow( this );" />

function removeRow( chk )
{           // <tr>        <table>
var i = chk.parentNode.parentNode.rowIndex;
           chk.parentNode.parentNode.deleteRow(i);
}

 

adding onchange( this )

Link to comment
Share on other sites

I'd use an onChange (so it works for keyboard navigation as well)

 

Most (all?) browsers interpret onclick as hitting enter while tabbed onto an element in addition to clicking the mouse, so onclick and onchange are equally accessible in this situation.  It's just with onmouseover and other mouse-specific functions that you need to include a keyboard equivalent.

 

But other than that, yeah, what Axeia said. :)

Link to comment
Share on other sites

I'd use an onChange (so it works for keyboard navigation as well)

 

Most (all?) browsers interpret onclick as hitting enter while tabbed onto an element in addition to clicking the mouse, so onclick and onchange are equally accessible in this situation.  It's just with onmouseover and other mouse-specific functions that you need to include a keyboard equivalent.

Don't ask me for a source but I remember some mobile browser not doing so.

But really you want to change it when the value chances, so using onchange makes the most Sense.

 

This example works in both Firefox and Konqueror:

<html>
  <head>
  </head>
  <body>
   <table border="1">
     <tr>
       <td>Remove me</td>
       <td><input type="checkbox" onchange="removeRow( this )" /></td>
     </tr>
     <tr>
       <td>Or me</td>
       <td><input type="checkbox" onchange="removeRow( this )" /></td>
     </tr>
   </table>
  <script type="text/javascript">
      function removeRow( chk )
      {             // <tr>       <table>    <dunno>    <tbody>
        var i = chk.parentNode.parentNode.rowIndex;
	             chk.parentNode.parentNode.parentNode.parentNode.deleteRow(i);
      }
   </script>
  </body>
</html>

 

Seems like there's some more nodes to move up to ;) just use and alert instead of deleterow

alert(chk.parentNode.parentNode)

and keep adding .parentnode behind it till it alerts you with a tablecell, then use that to do the deleteRow on. (Or give the table an ID and then do

Document.getElementById( 'tableId' ).deleteRow(i);

Which is probably a better approach as both Konqueror and Firefox seem to be adding a <tbody> and another mysterous element.. and I'm not sure as to how other browsers handle it.. so it might results in having to move up a different amount of parentnodes.

Link to comment
Share on other sites

You could use a cookie to delete it again on the next pageload, but permanently.. no.

Unless this is somewhere where users are logged in, in which case you can use Ajax (store the setting on the server)

Link to comment
Share on other sites

Don't ask me for a source but I remember some mobile browser not doing so.

 

Thanks, good to know.  I seriously need to learn more about mobile browsers.

 

Gangster, do you want the changes to affect everyone who views the site, or just that specific person?  You can set a cookie if you only want the changes to be visible to that person.  Otherwise you're going to need either a database or a file or something on the server that keeps track of what's been changed.  If you really don't want to use sql, you can always write the changes out to a text file.  (Read this for more info: http://www.tuxradar.com/practicalphp/8/0/0)  For security purposes, though, it really would be better to use a database.

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.