Are there any javascript experts in the house?

Started by Eristic, December 18, 2007, 10:41:45

Previous topic - Next topic

Eristic

I need a fix for a javascript function to read an array of form values. If there is anyone with good js knowledge I'll post details.

Thanks.

Eristic


Uncle Joshua

I have no clue with javascript but if you PM me what you need I'd be happy to ask the comp geeks on my forum.

kenkew

Maybe you could post Hot Potato's query, too, Mick?
(See Pic Resize on this board)
Ken.

Uncle Joshua

#3
Quote from: kenkew on January 07, 2008, 11:44:21
Maybe you could post Hot Potato's query, too, Mick?
(See Pic Resize on this board)
Ken.

Will do ken, can guests view the forum? if so I can just post a link rather than typing it all up.


Eristic, could you post the script here?

kenkew


Eristic

I've managed a workround for the time being but the problem was the failure of a js function to properly read the state of arrays of checkboxes in a form vis:

HTML code generated pragmatically from server

Bla bla
<input name="colour[]" value="red" checked="checked" />
<input name="colour[]" value="white"  />
<input name="colour[]" value="blue  />
Bla bla


js script called by onclick event.

function getformvalues (fobj, valfunc){

var str = "";
aok = true;
var val;

//Run through a list of all objects contained within the form.
for(var i = 0; i < fobj.elements.length; i++){
if(valfunc) {
if (aok == true){
val = valfunc (fobj.elements[i].value,fobj.elements[i].name);
if (val == false){
aok = false;
}
}
}
str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
}
//Then return the string values.
return str;
}


The function shown is just one of several as part of an Ajax call to the server. The problem is that while this function is reading text inputs correctly, it sees every checkbox as ticked regardless of user input or initial server settings. The form would work properly when submitted manually.

Obviously I have to test for checkboxes separately and read their settings within an if block but nothing I tried gave the correct result. If anyone knows a simple route round this problem it would be nice to know as my kludge involved rewriting a number of forms to process the checkboxes separately and in a different manner that also involved a lot of extra serverside work and extra database calls and tests, but I am up and running so do not stay up late staring at it.

Baccy Man


Uncle Joshua

That code should work Eristic, the only thing I can see is that the variables  may need changing.

We'll keep working at it and let you know ASAP.

Powered by EzPortal