?
Solved

Javascript: Find and Enable Submit Button in Table

Posted on 2016-11-16
3
Medium Priority
?
94 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 58

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 58

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

777 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