Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Javascript: Find and Enable Submit Button in Table

Posted on 2016-11-16
3
Medium Priority
?
108 Views
Last Modified: 2016-11-17
I have a dynamically created table. Each row of the table includes form elements. It includes a drop down and a submit button.
The submit button is disabled by default and I want in enabled when I change the drop down.
The following function works great in making changes and calculation on the other data in the row, but I can't seem to get the SubmitButton to enable. Can someone tell me what I'm doing wrong?

// Chnages Op on rank change
	$(".rank").change(function() {
    var $rankop = this.value; // get Rank value
    var $catrow = $(this).closest("tr");    // Find the row
    var $catop1 = $catrow.find(".catop").text(); // Find cat Op
	var $baseop = $catrow.find(".baseop").val(); // Find baseop
	var $catop = ($rankop * $baseop); // Multiply ranking x op for new op 
	    $catop =$catop.toFixed(2);    // format to 2 decimal points
		
	$catrow.find(".rankop").val($rankop); // change value of hidden field calcop for form submit
	$catrow.find(".calcop").val($catop); // change value of hidden field calcop for form submit
	$catrow.find(".catop").text($catop); // change text of catop cell to new op
	$catrow.find(".SubmitButton").disabled = false; // Enable Submit Button. This is part that does not work

});	

Open in new window

0
Comment
Question by:dannyg280
  • 2
3 Comments
 
LVL 60

Accepted Solution

by:
Julian Hansen earned 2000 total points
ID: 41889621
If youre table is dynamic - do you mean in the browser or in how it is rendered on the server?

You may be running into the problem of binding to the row before it is created. Try changing this (Line 2)
$(".rank").change(function() {

Open in new window

To this
$('body').on('change', '.rank', function() {

Open in new window

With the above change - even if you add rows to the table in the browser the change event will fire.
0
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 41889623
Also change your line 13 to this

$catrow.find(".SubmitButton").prop({disabled: false});

Open in new window


Use the prop() method
0
 

Author Closing Comment

by:dannyg280
ID: 41891603
Perfect. Thank you
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question