/    Sign up×
Community /Pin to ProfileBookmark

check the checkbox status when page loads up

Hey gang

In my “create new item” form, i have a checkbox that if it is checked, a textarea willl be pop up for me to type something. if I go to “update item” form, i want that checkbox to be checked and also the textarea to be shown with what I typed when I created the item.

I guess my question is how to call a textareaPop() javascript function if the checkbox is checked at page load.

Thanks in advance

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@mdjoOct 31.2007 — 
In my "create new item" form, i have a checkbox that if it is checked, a textarea willl be pop up for me to type something. if I go to "update item" form, i want that checkbox to be checked and also the textarea to be shown with what I typed when I created the item.

I guess my question is how to call a textareaPop() javascript function if the checkbox is checked at page load.
[/QUOTE]


My first question would be what you're doing to get the checkbox checked on the return. I presume you're using PHP or ASP or JSP or something. Why not just use the same flag to turn on the textbox? Life if you're writing:

<i>
</i>&lt;input type=checkbox name=fooCheck &lt;%= boxWasChecked?" checked":""%&gt;&gt;


then later just write
<i>
</i>if (boxWasChecked)
{
%&gt;
&lt;textarea name=fooText&gt;&lt;%= fooText%&gt;&lt;/textarea&gt;
&lt;%
}


But if you really need to test this with Javascript for some reason, the simple answer is, use

<i>
</i>if (document.getElementById("fooCheck").checked)
textAreaPop();
Copy linkTweet thisAlerts:
@jj0914authorOct 31.2007 — Thank you for replying.

I guess I wasn't clear on my question, what I want is when I load the page, I need to call the JS function, but since I already used <body onload=""> to call other JS function, so I am not sure how I can call this textarePop() function at page load
Copy linkTweet thisAlerts:
@mdjoOct 31.2007 — Oh, sorry, I completely misunderstood what you were asking. You just want to know how to have two functions run at <body onload> time? Easy.

Suppose the two functions are called "stuff" and "moreStuff".

Option 1:
<i>
</i>&lt;body onload="stuff();moreStuff();"&gt;


Option 2:
<i>
</i>&lt;script&gt;
function allStuff()
{
stuff();
moreStuff();
}
...
&lt;body onload="allStuff()"&gt;
Copy linkTweet thisAlerts:
@jj0914authorOct 31.2007 — Thanks a lot buddy, that's exactly what I want to know. : )
×

Success!

Help @jj0914 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...