Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Help - Checking Select Checkbox 2

Status
Not open for further replies.

cfinitialize

IS-IT--Management
Feb 26, 2008
29
US
I've searched google and this forum to find an answer but no luck at all... partly, maybe because I don't know how to word the search correctly.

Essentially, here's what I'm trying to accomplish: I have a form with dynamic names and data for each input - I have the Check All/Uncheck All javascript working. What I want to accomplish is to check select checkbox based on the type of appStatus. Here's part of the code:



<cfform name="appReqLine" action="appLtr.cfm" method="post">
<cfset total_records = qryJOBREQ.RecordCount>
<cfloop index="Counter" from="1" to="#total_records#">

/* the checkbox input
<cfinput name="applicantID" type="checkbox" onClick="chglnk('chktd',this.form)" value="#Counter#" checked="no" >

<cfinput type="hidden" name="appID_#Counter#" value="#Trim(appDetail[Counter][1])#" />
<cfinput type="hidden" name="reqID_#Counter#" value="#Trim(appDetail[Counter][11])#" />
<cfinput type="hidden" name="reqDesc_#Counter#" value="#Trim(appDetail[Counter][12])#" />
<cfinput type="hidden" name="namePrefix_#Counter#" value="#Trim(appDetail[Counter][2])#" />
<cfinput type="hidden" name="firstName_#Counter#" value="#Trim(appDetail[Counter][4])#" />
<cfinput type="hidden" name="lastName_#Counter#" value="#Trim(appDetail[Counter][3])#" />
<cfinput type="hidden" name="addr1_#Counter#" value="#Trim(appDetail[Counter][5])# #Trim(appDetail[Counter][6])#" />
<cfinput type="hidden" name="addr2_#Counter#" value="#Trim(appDetail[Counter][7])#, #Trim(appDetail[Counter][8])# #Trim(appDetail[Counter][9])#" />
<cfinput type="hidden" name="reDate_#Counter#" value="#DateFormat(appDetail[Counter][13], 'mm/dd/yyyy')#" />
<cfinput type="hidden" name="dateApp_#Counter#" value="#DateFormat(appDetail[Counter][14], 'mm/dd/yyyy')#" />


/* this input is what I'm trying to use to determine which checkbox need to be checked... (ie. Check all checkbox where status == 'NQ')

<cfinput type="hidden" name="appStatus_#Counter#" value="#Trim(appDetail[Counter][10])#" />

</cfloop>

</cfform>




// query output

--------------------------------------------------------------------------------

PRINT NAME HISTORY STATUS DATE

105 HILL, . JPRT HISTORY AI 02/19/2008

104 KRINGLE, . KRIS HISTORY DM 02/19/2008

103 DOE, MR. THOMAS HISTORY NQ 02/19/2008

107 DOE, MR. JOHN HISTORY NQ 02/25/2008

100 TESTING, MS. MARIA HISTORY FY 02/19/2008

I hope that make sense? I'm just really stomped, specially that the name of the input is dynamic.
 
If your question is a javascript question (which I'm starting to think that it's not) then you're going to have to post code that we can understand. I've never used cold fusion (thank god) and it's likely that many of the other javascript experts here have not either. If you want us to debug your javascript issues it would be helpful if you posted the client side code that you are having problems with - that way we don't have to try and figure out what is being served to the client.

Now, with specific regard to your question, it seems like you're trying to determine which checkboxes need to be automatically checked when the page loads. Javascript should not be used for this. Your server side language of choice (cold fusion) is more than capable of doing this, and would be a more secure solution. I'd suggest that you repost this question in that forum.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
coldfusion is not as bad as you think, kaht and yes, it is a javascript problem and it's not an "onload" or page load script that I'm trying to create.

let me try and explain it better.

I want to create a link: <a href="javascript:SelectNQ()">NQ</a> that when click will check all records with appStatus input = NQ.

This input:
<cfinput name="applicantID" type="checkbox" onClick="chglnk('chktd',this.form)" value="#Counter#" checked="no" >

when page loads:
<input name="applicantID" type="checkbox" value="1" checked="no" >
<input name="applicantID" type="checkbox" value="2" checked="no" >
<input name="applicantID" type="checkbox" value="3" checked="no" >
<input name="applicantID" type="checkbox" value="4" checked="no" >
<input name="applicantID" type="checkbox" value="5" checked="no" >

This input:

<cfinput type="hidden" name="appStatus_#Counter#" value="#Trim(appDetail[Counter][10])#" />

essentially are named dynamically when the page is loaded depending on how many records there are:

<input type="hidden" name="appStatus_1" value="DN" />
<input type="hidden" name="appStatus_2" value="NQ" />
<input type="hidden" name="appStatus_3" value="IS" />
<input type="hidden" name="appStatus_4" value="NQ" />
<input type="hidden" name="appStatus_5" value="NQ" />

What I want to happen is when the javascript link "NQ" is checked, checkboxes 2,4,5 will be checked.

I don't have anything started yet. The only solution I found online is for checking/unchecking ALL.

I hope that makes sense?
 
I always use the server-side scripting to set the state when the page loads, so I agree with kaht that you should use Coldfusion to do this.

If you really want to do this client-side, we're not going to write the code for you, but will help you if you show us what you've done yourself.

Lee
 
trollacious, I wouldn't even know where to start and what you mean by "server-side scripting" much less starting a javascript program. nonetheless, thank you both for your time.

 
There's a lot of problems with setting it up like this. First, there's nothing that will automatically differentiate these hidden inputs from other hidden inputs to javascript. The best I can think of is to loop through the entire list (get them all using [!]getElementsByTagName("input")[/!]) and check against the name attribute of each to see if the first part of the name substring is "appStatus_". If it is, then check it's value to make sure it's NQ. Afterwards, you have to pull the number from the name (after the appStatus_ part of the name) - personally I'd use a regex with the replace method to do this. Now that you have the number pulled from the hidden input, there's still no easy way to get to the checkbox. You have to pull the list of checkboxes (this time, I'd use [!]getElementsByName("applicantID")[/!]) and loop through them all to see if any of their values match the number you extracted from the hidden input's name. When you find that element, set it's .checked property to true.

Honestly, the naming scheme for your elements do not make this a very easy process.... There's a lot more looping required than needs to be. It will likely still run fast enough to not be noticeable to a user, but still....

Go ahead and take a stab at writing the function the way I described above. If you have problems with it post back here with what you've completed and we'll give you some help.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Thanks for the input. I'll try and see what I can come up with.
 
There are several ways to do this:
Code:
var prefix = 'appStatus_';
var appstatvalue = hiddenvalue.replace(prefix, '');
or
Code:
var prefix = 'appStatus_';
var appstatvalue = hiddenvalue.substr(hiddenvalue.indexOf(prefix) + prefix.length);

You'll have to adapt this to however you've written your code, this is just an example of how to access a portion of a string.

Lee
 
so either one of those will REMOVE the prefix "appStatus_" and leave the value after?

beforeValue = appStatus_6
afterValue = 6

is that right?
 
is that right?

I'm a big proponent of the idea that if you try something yourself, you'll have a much better chance of remembering it for later. Give it a shot and see what happens. If it doesn't produce what you expect, work off the output that you do get and try to make it fit your needs.

On a side note, I would go with Lee's first example using the replace method - I find it a bit more elegant. I always forget that the first parameter of that method can accept a string in addition to regexp, so if you aren't well versed with regexp you can opt for the string parameter instead.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
i'm merely repeating trollacious' directions. if someone gives me directions on how to get to someone's house, it's always a good idea to repeat it to make sure I understand what the other person said. NOT drive and find out later that I misunderstood part of parts of the directions.

btw. I wasn't able to produce any ouput. instead I got javascript error. you know why? because I don't know what I'm doing. because I'm not as well-versed as you, kaht.

do you always make people feel stupid because they asked questions? or repeat what you say in a manner that they could understand?

nevermind the script. i've given up. i'll find some other way to patch what I want accomplish.

thank you for your time.

 
You'll have to adapt this to however you've written your code, this is just an example of how to access a portion of a string.

You haven't shown your JS code to give us ANY idea what you have already. If you need someone to write this for you, there are other venues to make that request in other than Tek-Tips.

Lee
 
i can't even get the value of any field...


var cond = 0;
function lnkChkNQ(tdid,frmname) {
frmobj = document.forms[frmname];
elmlen=frmobj.length
for(i=1;i<elmlen;i++) {
if(frmobj.elements.type=="input") {
var prefix = 'appStatus_' + i;
var appValue = document.getElementById(prefix).value;

alert("the value is " + appValue);

} //end for


if( cond == 0 ) {
document.getElementById(tdid).innerHTML="<a href=\"javascript:lnkChkNQ('chkNQ','appReqLine')\">NQ</a>"
cond=1
} //end if
else {
document.getElementById(tdid).innerHTML="<a href=\"javascript:lnkChkNQ('chkNQ','appReqLine')\">NQ</a>"
cond=0
} //end else
} //end function

 
If you copied and pasted your code in here, your //end for brace is actually an end if brace.

Lee
 
nevermind. i forgot i commented the line to call the script. but when I click the link to run the script, nothing happens. no alerts, but no errors either.
 
Try it in Firefox and see what the error console tells you. That's MUCH better than the error help in IE.

Lee
 
if someone gives me directions on how to get to someone's house, it's always a good idea to repeat it to make sure I understand what the other person said. NOT drive and find out later that I misunderstood part of parts of the directions.

That's a very good point. You know why? Because it would be much faster to ask someone over the phone for the directions instead of spending 15 mins driving to the wrong directions.

This point only further drives home what I was saying above. It would have been much faster for you to apply Lee's changes (probably less than 2 mins) to see what happened, rather than post back asking for confirmation and hoping that he happens to be reading the message board at that same time so that you get a quick response - which usually doesn't happen. Take my post for example, I'm just now replying an hour after you posted your analogy because I haven't been on the forum for the last hour. If it was my suggestion instead of Lee's, you could have spent that hour trying all kinds of different things to get it to work, and likely you probably would have learned a few things about the replace method in the meantime, even if you didn't get your code to work. Also likely that you would remember them for the next time that you need to use that tool. "Teach a man to fish" they say....

btw. I wasn't able to produce any ouput. instead I got javascript error. you know why? because I don't know what I'm doing. because I'm not as well-versed as you, kaht.

I'm sorry, but you never once mentioned that you are a beginner in javascript. How are we supposed to know that? I usually assume that most people are somewhat versed in javascript unless they say otherwise - it says at the top of this site that it's "INTELLIGENT WORK FORUMS FOR COMPUTER PROFESSIONALS" - if you're not a javascript professional you should have just said so from the beginning and the advice you got would have been more tailored toward a beginner.

do you always make people feel stupid because they asked questions?

The intention of my post was not to make anybody feel stupid. I can not tell you how many times people have come to this site essentially expecting you to write their program for them. I'd say it happens at least once every 1 or 2 days. I've been on this site for a long time and have come to expect it from a lot of users. I'm not saying that you fit this mold, but from what I've experienced in the past it has caused most of my advice to come in the form of self help. I'll guide anybody that asks for guidance, but if someone comes here expecting a hand-out then they won't get much help from me. I spend too much time giving free consultation on this site to bother with people that won't help themselves.

Again, I'm not saying you fit this mold. You actually seemed to take my initial advice and use that as a template - which shows that you had enough initiative to code on your own. That's more than I can say for a lot of the morons that stumble onto this site.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
I wouldn't even know where to start and what you mean by "server-side scripting" much less starting a javascript program. "

true, the word beginner isn't in that sentence - but i thought anyone reading that would understand.

but I get your point, kath.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top