/    Sign up×
Community /Pin to ProfileBookmark

Javascript String/Array Confusion

I currently have a form that calls a query to dynamically create the form fields and value of checkboxes using coldfusion and javascript. What I have coded submits any boxes checkd by the user, but what I want to pull and pass to the next page are the selected checkboxes, plus the disabled fields. I tried adding checkbox.disabled to the logic, but either that won’t work or my syntax or logic was off. (well, I guess that was an obvious statement)
I figure I can go two ways, although have not been able to do either. Since the list of disabled fields is a list, I figured I could put it into an array and then append each element to the existing list, but it was not successful… then I thought I could somehow use the logic to also add the values of the disabled items, which also did not work. Could someone maybe point me in the right direction? I appreciate any help and your time!

Rough form code is (this is coldfusion but gives you an idea of where I am pulling my form data from, the question really is javascript mostly):

[code]
<cfloop query=”q_so1_list” startrow=”1″ endrow=”#q_so1_list.recordcount#”>
<cfif ListFind(tr_pick_so1, so1_cd)>
<input type=”checkbox” name=”pick_so1″ value=”#so1_cd#” checked disabled>
<cfelse>
<input type=”checkbox” name=”pick_so1″ value=”#so1_cd#”>
</cfif>
</cfloop>
<cfloop query=”q_so2_list” startrow=”1″ endrow=”#q_so2_list.recordcount#”>
<cfif ListFind(tr_pick_so2, so2_cd)>
<input type=”checkbox” name=”pick_so2″ value=”#so2_cd#” checked disabled>
<cfelse>
<input type=”checkbox” name=”pick_so2″ value=”#so2_cd#”>
</cfif>
</cfloop>
[/code]

Rough submit code is:

[code]
for(var i = 0; i < pick_so1.length; i++){
if(document.form1.so1[i].checked)
so1_nm = so1_nm + String.fromCharCode(1) + String.fromCharCode(2) + pick_so1[i].value;
pick_so1.checked = true;
}
for(var i = 0; i < pick_so2.length; i++){
if(document.form1.so2[i].checked)
so2_nm = so2_nm + String.fromCharCode(1) + String.fromCharCode(2) + pick_so1[2].value;
pick_so2.checked = true;
}

so1_nm_list.value = so1_nm + String.fromCharCode(1) + String.fromCharCode(2);
so2_nm_list.value = so2_nm + String.fromCharCode(1) + String.fromCharCode(2);
return true;
[/code]

Also, my quick array code was something like:

[code]
var a = new Array();
a = tr_pick_so1.split(/,/);

for(var k = 0; k < a.length; k++){
so1_nm_list.value = a[k] + String.fromCharCode(1) + String.fromCharCode(2);}
[/code]

That caused undefined syntax errors…

Thanks again for any help!!!
Va.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@KorJul 11.2007 — Welcome to the Form. For the future, please, wrap your codes, it is easier to be followed.

On the other hand... It is not clear for me, it is ColdFusion (I presume) problem, or a javascript one? If it is a javascript problem, the generated HTML code would be more helpful, not the CF one, as javascript works with the generated HTML elements, so that we need to see [I]them[/I] at work.

At a first glace, I don't think that you may split a string upon an object ([B]/,/[/B]). In javascript, Regular expressions are objects, thus try a [B]split([COLOR="Blue"]','[/COLOR])[/B] upon a string. Or use the [B]RegExp()[/B] object ...
Copy linkTweet thisAlerts:
@Banana_AnandaJul 11.2007 — The split method does accept a regular expression (handy sometimes), but it's wasted here. [COLOR="Blue"]","[/COLOR] serves the same purpose.

I agree about the ColdFusion. We want the HTML !
Copy linkTweet thisAlerts:
@KorJul 11.2007 — The split method does accept a regular expression (handy sometimes), but it's wasted here. [COLOR="Blue"]","[/COLOR] serves the same purpose.
[/QUOTE]

Yes, but you the quote: "make it simple..." ?
×

Success!

Help @ironyx spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...