Forum Moderators: open

Message Too Old, No Replies

Help with Javascript function

         

xKillswitchx

9:49 pm on Dec 30, 2007 (gmt 0)

10+ Year Member



I had a list of functions that would allow me to submit my form with different actions, depending on which submit was pressed. It ended up being many functions, and I wanted to trim it down to one, but I don't know Javascript at all. This is what I have gotten so far...

// adminForm submittion
function editItem(do, action)
{
document.contentForm.action = "?do=" +do "&action=" +action
document.contentForm.submit(); // Submit the page
return true;
}

The original had no arguments passed and simply set the action to something specific, here is the old...

// adminFrom submittion
function editItem()
{
document.contentForm.action = "?do=sections&action=edit"
document.contentForm.submit(); // Submit the page
return true;
}

Is the above correct? I am not quite sure if thats how to use concatenation (sp?) with Jscript. Also, what I am using this for, I have a table listing items from a database, each with a checkbox. I want to be able to check multiple boxes and click a button to send all to edit, or all checked items to a delete process. I also want to use this along side of XAJAX. Is this a good way to go about this? All the do and action in the URL is are php functions controlled by SWITCH. Each (most) function has their own extra function to process teh data, which is what I have been using XAJAX for, the process end.

PS - I know some say you shouldn't submit forms with Javascript, but I am not worried about those that choose not to enable it. This is a project I will be using often and those that do use it will have Javascript enabled (or will enable it).

daveVk

12:29 am on Dec 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



document.contentForm.action = "?do=" + do + "&action=" + action

A more direct way

<INPUT type="submit" name="action" value="edit">
<INPUT type="submit" name="action" value="clone">