0

I am working on a project using the Spring MVC framework, and am currently stuck on figuring out how to disable submit buttons that have been produced from a for each loop (written in spriptlets). I know that scriptlets are considered bad practice, but the company I'm training at doesn't seem to care...

Anyways, here is my for loop:

<%for(Aj aj : ajList) {%>
    Job Name: <%=jobDao.getById(aj.getJobId()).getTitle() %><br/>
    Current Status: <%=statusDao.getById(aj.getStatusId()).getStatusName() %><br/>
    <input id="notQualified[<%=aj.getStatusId()%>]" class="notQualified[<%=aj.getStatusId()%>]" name="notQualified[<%=aj.getJobId() %>]" value="Not Qualified" type="submit" />
    <input id="qualified[<%=aj.getStatusId()%>]" class="qualified[<%=aj.getStatusId()%>]" name="qualified[<%=aj.getJobId() %>]" value="Make Qualified" type="submit" />
    <input id="interview[<%=aj.getStatusId()%>]" class="interview[<%=aj.getStatusId()%>]" name="interview[<%=aj.getJobId() %>]" value="Interview" type="submit" />
    <input id="hire[<%=aj.getStatusId()%>]" class="hire[<%=aj.getStatusId()%>]" name="hire[<%=aj.getJobId() %>]" value="Hire" type="submit" /><br/><br/>
<%}%>

And here is the jquery I've written thus far:

$(function() {
    $('.notQualified[<%=1%>]').attr('disabled', 'disabled');
    $('.interview[<%=1%>]').attr('disabled', 'disabled');
    $('.hire[<%=1%>]').attr('disabled', 'disabled');
    $('.qualified[<%=2%>]').attr('disabled', 'disabled');
    $('.interview[<%=2%>]').attr('disabled', 'disabled');
    $('.notQualified[<%=3%>]').attr('disabled', 'disabled');
    $('.qualified[<%=3%>]').attr('disabled', 'disabled');
    $('.interview[<%=3%>]').attr('disabled', 'disabled');
    $('.hire[<%=3%>]').attr('disabled', 'disabled');
    $('.qualified[<%=4%>]').attr('disabled', 'disabled');
    $('.hire[<%=4%>]').attr('disabled', 'disabled');
});

So, if it isn't clear, I am working with 4 different statuses. If the "aj" (a table in the database that connects users with jobs they've applied to and the status of the job for that user) being iterated corresponds to the 1st status, disable the "not qualified," "interview," and "hire" buttons. Etc. I would appreciate any help.

Nick Gent
  • 13
  • 4
  • What's the actual problem? And do you not have variables for the four different statuses you mention? Server-side code `<%=1%>` is pointless when the constant could just be included directly as `1`, but presumably that's where you want to check these status values? Also, why are you assigning classes with names identical to the ids? – nnnnnn Feb 22 '12 at 20:31
  • I was playing around with this a little, so it is a bit messy. I tried using the actual number 1 in my jquery (ie: '.notQualified[1]') but that didn't work. As for the ids having the same name as the classes, that was because I had switched over from using the ids in the jquery to using the classes, and I forgot to remove the "[<%=aj.getStatusId()%>]" from the end of each id. And my problem is that none of the buttons are being disabled as they should be. I can either get the first set of buttons to become disabled or none at all... – Nick Gent Feb 22 '12 at 20:41
  • Try using \\ to escape those [ ]. check http://stackoverflow.com/a/9402472/297641 - that is exactly what you need. – Selvakumar Arumugam Feb 22 '12 at 20:46
  • Don't remove `[<%=aj.getStatusId()%>]` from the end of the ids. Ids need to be unique on the page, but obviously if you remove the numbering you'll have duplicate ids. Id is for identifying unique things, class is for identifying groups of things. (Though I'd remove the square brackets just due to my personal preferences about id style.) Using the actual number `1` will give exactly the same result as `<%=1%>` (use View Source in your browser to compare). – nnnnnn Feb 22 '12 at 21:02
  • @nnnnnn Thanks for your help- I removed the square brackets from my classes (and left them in the ids) and now it works like a charm. – Nick Gent Feb 23 '12 at 14:06

1 Answers1

0

The trouble I was having came from the square brackets I had around the status id. Once I removed those, everything worked fine.

Nick Gent
  • 13
  • 4