/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Function not working when passing in an id

I am trying to call a function:

hide($tempIdNum) {
$divString = $tempIdNum . “div”; //Buttons id’s=$tempIdNum related div boxes id’s=$tempIdNum . “div”
echo “<script type=’text/javascript’>
document.getElementByID(” . $divString . “).style.visibility = ‘hidden’; //Hide the related div box
</script>”

using:

echo “<input type=’button’ name=’hide’ id='” . $idNum . “‘ onClick=’hide(” . this.id . “)’ />”

There must be an error when the button tries to call the function because I’ve tried doing… echo “<p>This Function is Working</p>”; in the function just for debugging purposes and it doesn’t write it anywhere when I click the button. Anyone know what I’m doing wrong?

Any help is appreciated.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@Phill_PaffordAug 28.2008 — Looks like you are trying to combine JavaScript and PHP and calling the PHP function from the onclick event which I don't think you can do.

Looking over your code you just want to hide the div when the button is clicked try this site

Harry Maugans it has a nice toggle function.
Copy linkTweet thisAlerts:
@drhart4000Aug 30.2008 — Ok, Im not sure exactly what your trying to do... but heres some code, maybe it will help...

This should be in the header of your page. NOTE: this is what javascript should look like.
[CODE]
<script type="text/javascript">
function hide(divID) {
document.getElementByID(divID).style.visibility = 'hidden';
</script>[/CODE]


This should be in your php to echo the div number(i assume '$tempIdNumb' is the div id, change this if im wrong). It will call the javascript function and give it the right id.

[code=php]<?php
echo "<input type='button' name='hide' id='".$idNum."' onClick='hide('".$tempIdNum."');' />";
?>[/code]
×

Success!

Help @sklink 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.28,
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,
)...