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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form action 1

Status
Not open for further replies.

FumacII

Programmer
May 11, 2001
11
SE
Hi,

I have a form with diffrent inputs.
A perl script prints out a list with checkboxes, so I never know how many checkboxes there are.
Now I want to put all values from the checked boxes in a string when the form is submitted.
Is there any possibility to use a javascript function as action to the form?

Thank you for any reply

/Fumac
 
Hi,
U can do it this way,

first find the length of the check boxes,

for (i=0; i<checkbox.lenght;i++){

var val = document.formname.checkbox.value

}
 
Hi,
U can do it this way,

first find the length of the check boxes,

for (i=0; i<checkbox.lenght;i++){

var val = document.formname.checkbox.value

}

Thanx

B Reddy
 
Well, what you do is this... where normally you would put a submit button, you make it a regular button and point it to a function:

<input type=button value=Submit onClick=&quot;yourFunction();&quot;>

So then your function would look like:

<script language=javascript>
function yourFunction(){
//do what you need to, and then,
document.formName.submit();
}
</script>

:)
Paul Prewett
penny.gif
penny.gif
 
Thanx,
But I only want the values from the boxes that are checked. All other boxes values are not to be there.
It´s a list with files and all the files that are checked will be deleted.
The value of each checkbox is the id of the file (from an database).
Doesn´t I have to submit the form to know which boxes that are checked? Or can I do it in my javascript function?

/Fumac
 
Here is a solution to all your problems and as link9 said you could call the onsubmit action in a function and us the scripe below to extract the values of the checkboxes.


<FORM>
<INPUT TYPE=&quot;CHECKBOX&quot; NAME=&quot;one&quot; VALUE=&quot;one&quot;>
<INPUT TYPE=&quot;CHECKBOX&quot; NAME=&quot;two&quot; VALUE=&quot;two&quot;>
<INPUT TYPE=&quot;CHECKBOX&quot; NAME=&quot;three&quot; VALUE=&quot;three&quot;>
<INPUT TYPE=&quot;CHECKBOX&quot; NAME=&quot;four&quot; VALUE=&quot;four&quot;>
<INPUT TYPE=&quot;CHECKBOX&quot; NAME=&quot;five&quot; VALUE=&quot;five&quot;>
<INPUT TYPE=&quot;CHECKBOX&quot; NAME=&quot;six&quot; VALUE=&quot;six&quot;>

<INPUT TYPE=&quot;BUTTON&quot; onClick=&quot;cycleCheckboxes(this.form)&quot; VALUE=&quot;Check&quot;>
</FORM>

<SCRIPT LANGUAGE=&quot;JavaScript&quot;><!--
function cycleCheckboxes(what) {
var tmp=&quot;&quot;;
for (var i = 0; i<what.elements.length; i++) {
if (what.elements.checked) {
tmp= tmp + &quot; &quot; + what.elements.value;
}
}
alert(tmp);
}
//--></SCRIPT>


;-)
 
Bullseye!

Thank you nitinkhanna!
That solved my problem, many thanks!

/Fumac :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top