Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old May 30th, 2005, 09:46 PM
mrweb mrweb is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 6 mrweb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old May 31st, 2005, 12:21 PM
mrweb mrweb is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 6 mrweb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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;
}

Reply With Quote
  #3  
Old June 1st, 2005, 12:47 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
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...

Reply With Quote
  #4  
Old June 2nd, 2005, 09:19 PM
mrweb mrweb is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 6 mrweb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: passing a form name to javascript

it does. thanks very much

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > passing a form name to javascript


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT