/    Sign up×
Community /Pin to ProfileBookmark

Newbie problem with php and javascript

I hope someone can help me here. I’m a PHP type of guy rather than javascript but I found some nice JS that I want to use on my page together with some php coding.

The problem seems to be that the JS code won’t pass some of my php code to the server properly and I don’t know how I can get around it.

Heres the script in the header:

[code]
<script type=”text/javascript”>
// <![CDATA[

// Tab menu functions by Jack Letourneau, February 2002
// [url]http://eigengrau.com/[/url]

function switchOn(tab,contents) {

// Pass it a tab ID and a contents ID, single-quoted:
// switchOn(‘tab1′,’contents1’)

// Sets all tabs and contents to inactive state, then
// activates the tab/contents passed as parameters

switchAllOff();
document.getElementById(tab).className = ‘selectedtab’;
document.getElementById(contents).className = ‘selectedcontents’;
}

function clearTop() {

// Sets all tabs to inactive state. Depends on the TR
// enclosing the tabs having ID “toprow”

topRow = document.getElementById(‘toprow’);
tabArray = topRow.childNodes;
for (var i=0; i<tabArray.length; i++) {
if (tabArray[i].className != ‘tabspacer’) {
tabArray[i].className = ‘tab’;
}
}
}

function clearContents() {

// Hides all DIVs in TD ID=”contentscell”

contentsCell = document.getElementById(‘contentscell’);
contentsArray = contentsCell.childNodes;
for (var j=0; j<contentsArray.length; j++) {
contentsArray[j].className = ‘contents’;
}
}

function switchAllOff() {

// Trivial little wrapper function; sets all tabs and
// contents to inactive/invisible state

clearTop();
clearContents();
}

// ]]>
</script>
[/code]

And what I’m trying to do:

[code]
<table id=”tabmenu” border=”0″ cellpadding=”0″ cellspacing=”0″ width=”800″>
<thead>
<tr id=”toprow”>
<td class=”tab” id=”tab1″><div onclick=”switchOn(‘tab1′,’contents1’);”>What’s New</div></td>
<td class=”tabspacer”>&nbsp;</td>
<td class=”tab” id=”tab2″><div onclick=”switchOn(‘tab2′,’contents2’);”>Bulletin Board</div></td>
<td class=”tabspacer”>&nbsp;</td>
<td class=”tab” id=”tab3″><div onclick=”switchOn(‘tab3′,’contents3’);”>Technical Update</div></td>
<td class=”tabspacer”>&nbsp;</td>
<td class=”tab” id=”tab4″><div onclick=”switchOn(‘tab4′,’contents4’);”>Knowledge Base</div></td>
<td class=”tabspacer”>&nbsp;</td>
<td class=”tab” id=”tab5″><div onclick=”switchOn(‘tab5′,’contents5’);”>Useful Info</div></td>
</tr>
</thead>
<tbody>
<tr>
<td id=”contentscell” colspan=”9″>
<div class=”contents” id=”contents1″><?php include “update/view.php?category=training&playout=1″ ; ?></div>
<div class=”contents” id=”contents2″><?php include “forum/forumlist.php” ; ?></div>
<div class=”contents” id=”contents3″><?php include “test.php” ; ?></div>
<div class=”contents” id=”contents4″>Nihilne te nocturnum praesidium Palati, nihil urbis vigiliae…</div>
<div class=”contents” id=”contents5″>Nihil timor populi, nihil concursus bonorum omnium, etc.</div>
</td>
</tr>
</tbody>
</table>
[/code]

The problem is where I am trying to make the content of ‘contents2’ to be a php include. I want to call a php script and send some variables to it like ‘category=training&playout=1’ but although I can call the script okay as content – trying to add the extra variables to the string stops the javascript from working.

My question is how can I pass those variables through the javascript to the php page?

Hope I’ve explained that okay.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisNov 21.2003 — Do you mean that you use javascript on the client side to build a page that has PHP includes in it? The server has finished and closed the stream and gone home for the day by the time the js writes the page.
Copy linkTweet thisAlerts:
@Matt_PhelpsauthorNov 21.2003 — Not quite. The page itself is php. The javascript is just for the tab menu.

It's just like calling any php include but in this case I am dressing the content up with some javascript. The includes work fine if I don't try and pass extra variables as well.

I can call the include "view.php" and that fills the javascript content box with the result of that piece of code - in this case some text from a database. If I try and call the include like "view.php?category=training" then it falls over. The javascript doesn't seem to like the extra variables I've tried to pass to the view.php script.

I'm totally green when it comes to javascript but the problem seems to be that I'm assigning the class id "contents1" to be "view.php?category=training" and the javascript can't understand the question mark or the extra equals symbol in the string - or something.

Did I explain that any better?
×

Success!

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