Welcome Guest, Not a member yet? Register   Sign In
Javascript, Checkboxes & buttons problem
#1

[eluser]iloveci[/eluser]
Hello Everyone,

I have a tricky situation that I am trying to solve. My current solution is very dodgy and I need some assistance to fix it up.

I have a table of products with the following fields

checkbox, product name, product info, product price, & a submit button

The checkbox is used to filter through all the rows that are checked, in order to perform actions on multiple entries at once. However this required people to click the checkbox and some people forgot to and it resulted in problems.

So I wrote some simple javascript to enable the users to click anywhere in the table row, and it will select or de-select the row & display a selected class.

This works great EXCEPT when clicking the submit button, it counts as a click on the row and de-selects that row resulting in the action not working.

So my question is, Is there a better way to solve this problem? if so could you please give me a rough series of steps I'd need to do OR if you know a way I could disable the row click when a input button is clicked that would work too.

Thanks in advance,

iloveci
#2

[eluser]cideveloper[/eluser]
why wouldn't you just put one submit button right at the bottom? Then you wont have to worry about the row click and it will probably look a lot less cluttered not having all those submit buttons in your table.
#3

[eluser]tomcode[/eluser]
You can do something like this :
Code:
var onclickHandler = function(e) {
    if(e.target.getAttribute('type').toLowerCase() === 'submit') {
        // submit code
    } else {
        // row action code
    }
}

Won't work in IE unless used with a library like jQuery which normalizes the event object (param e)
#4

[eluser]iloveci[/eluser]
Thanks for the suggestions guys,

@progr@mmer I needed the buttons inline so that individual products could use the button.

@tomcode Thanks that was what I was after, I'm using jQuery but I'm new to writing my own javascript code rather than using pre-made plugins/code.




Theme © iAndrew 2016 - Forum software by © MyBB