|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
passing a form name to javascript
I've created a php page which creates a form for every record in the database, with a selection box (to select that record for comparison). When I do an "OnClick" I need to pass the form name to see if the box has been checked or unchecked.
However, I can't figure out how to pass the form name so I can check if document.formname.checkbox.checked is true or false. any ideas? Thanks |
|
#2
|
|||
|
|||
|
RE: passing a form name to javascript
I figured it out. If anyone else needs to know here is the solution.
All the forms on the page are passed to javascript as an array. If you know which number the form is (as when you create a form in a for/next loop) you can access the elements that way , as follows. function setclick(recnum, frmnum) { if (document.forms.frmnum].compbutton.checked) {alert("checked");} else {alert("unchecked");} return true; } |
|
#3
|
|||
|
|||
|
RE: passing a form name to javascript
there is an easier way where you do not need to know the form number or name. the function would look like this...
function setclick(recnum,objForm) { if (objForm.compbutton.checked) {alert("checked");} else {alert("unchecked");} return true; } and the onclick event in the check box would look like this onclick="setclick(4,this.form);" "this.form" sends a reference to the form that the checkbox element belongs too, so you dont need to know which form before hand. I hope that makes sense... |
|
#4
|
|||
|
|||
|
RE: passing a form name to javascript
it does. thanks very much
|
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Client Side Things > passing a form name to javascript |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|