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

Creating dynamic checkboxes when page loads

Status
Not open for further replies.

developer155

Programmer
Jan 21, 2004
512
US
Hi,
I need to create a bunch of dynamic checkboxes with JavaScript when page loads.
Can I do something like this?:
<script lang= javascript>
CreatCheckboxes(int zipcode)
{
//create checkboxes
}

</script>
<html>
....
<td>
CreatCheckboxes(zipcode);
</td>

thanks!!

 
You can, but you need to encapsulate the function inside script tags. Also, make sure the code that generates the checkboxes is done via document.write. If you're using another method (i.e. createElement) then you don't have to put the function call between the <td></td>
Code:
<script [!]type="text/javascript"[/!]>
CreatCheckboxes(int zipcode)
{
//create checkboxes
}

</script>
<html>
....
<td>
[!]<script type="text/javascript">[/!]
CreatCheckboxes(zipcode);
[!]</script>[/!]
</td>

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
thanks kaht,
so CreatCheckboxes() will be called when page loads? there is no need to add something like <body onload=CreateCheckboxes(zipcode)...>??

thanks
 
Yes, it will be called, but it doesn't need to be invoked from within the <td></td> tags. I saw from your other thread that you're not using document.write to generate the checkboxes, so you're likely going to need an onload function for the method you're using. That being the case, you can leave the function up in the head of the page.

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top