Solved

Javascript: Find and Enable Submit Button in Table

Posted on 2016-11-16
3
26 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 51

Accepted Solution

by:
Julian Hansen earned 500 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 51

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Phone Dialer 5 36
Angular - filter - one works but other doesn't 13 24
Bootstrap input box width 2 15
Bootstrap 3 icons 3 12
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now