View Full Version : Help with js menu pointing to php pages

08-13-2005, 04:22 AM

I'm not sure whether this fits here or whether it's really a php question but...

The following lines are from a js menu that I want to use on my site. However, both links return the same page although the second one should return the page for an individual category. Can anyone tell me whether it is possible to link to php pages in this manner? If so, how is it done?

document.write('</td></form><form action="categories.php"><td>');
document.write('<input type="submit" value=" Buy Online " onmouseover="this.className=\'buttonon\'" onmouseout="this.className=\'button\'" class="button"><br>');

document.write('</td></form><form action="categories.php?cat=1"><td>');
document.write('<input type="submit" value=" Artists " onmouseover="this.className=\'buttonon\'" onmouseout="this.className=\'button\'" class="button"><br>');

Many thanks

08-15-2005, 04:08 PM
That should work. I've done it before without any problems.
Perhaps it's your PHP on the handling page that is not correct.

08-15-2005, 04:30 PM
Many thanks for the reply.

I think that the PHP is OK. The javascript is in an external file but I have also tried inserting it directly into the page with the same result. If I view the source the correct link shows. I've also tried using the full path to the page but without success. All the other javascripts on the page work flawlessly.

08-15-2005, 09:12 PM
What happens if you type in the page directly with that param?
Does it show the right stuff?
Got URL?
Might be an issue with having multiple forms with no names or some such. I assume you only copied part of the page, since your forms have no (required) </form> tag.

08-15-2005, 09:38 PM
Thanks for the suggestion.

I have just tried adding the link categories.php?cat=1 as a hyperlink to some text on the page and it works perfectly.

I will now demonstrate my total ignorance of javascript.

The javascript is in a file menu.js which consists entirely of lines similar to the ones I gave earlier. At the position that the menu appears is simply the line <script language="JavaScript" src="menu.js"></script>.

All the buttons/links work perfectly except for ignoring the ?cat=*** at the end of some of the links.

An odd thing that I have just noticed is that the address bar in IE6 shows ? at the end of all page addresses (including html pages).

As a (hopefully) temporary work around I have cloned the affected pages and saved them as .htm and then changed the links in menu.js to link to them.

08-15-2005, 10:36 PM
An odd thing that I have just noticed is that the address bar in IE6 shows ? at the end of all page addresses

And what does it show for the ?cat=1 pages?

It is showing the ? at the end because what is really happening is a form submit, which is defaulting to get since method isn't specified.
That's why I mentioned the lack of </form> and such (which I see now is in fact there; I missed it).

Try this just for giggles. Change the lines to include the category as a hidden var and take it out of the action.

document.write('</td></form><form action="categories.php"><td>');
document.write('<input type="hidden" name="cat" value="1">');
document.write('<input type="submit" value=" Artists " onmouseover="this.className=\'buttonon\'" onmouseout="this.className=\'button\'" class="button"><br>');

08-15-2005, 11:05 PM
I take my hat off to you (or at least I would if I were wearing one). The fuller code works.

The ?cat=1 page shows just that, (following the .php of course).

I think I must be getting senile, on looking again at menu.js I find that there are other lines of code at the beginning and end of the script.

I notice that you have edited your post, but if you still want to see the code it is on a site that I am working on for a friend. I have uploaded my efforts so far to: http://www.windsorart.co.uk/ and the menu.js file is in the home directory.

I think I will replace the whole menu.js script with the extended version.

Once again, many thanks

08-16-2005, 03:37 PM
You're welcome!
I wanted to see the code because although making it a form field may fix the problem, I don't see why putting it in the action didn't work in the first place. Is till don't.
But glad you got it working.

I did notice that the menu is creating invalid html (no element may be a child of a TR except a TD, yet the forms are children of the TR) but that shouldn't have hurt anything. To make it valid, just move the <form> and </form> inside the TD instead of outside them.

Also, the categories pages are off in Firefox. The footer is left instead of centered and messes up. Don't know if you knew that.

08-16-2005, 08:31 PM
:( Just when I thought it was all going so well!!!

I think that I have now sorted the Firefox footer problem. I decided to make ithe footer 100% width.

I have also changed the menu.js and moved all the Form tags inside of the cell tags but that has caused its own problem with the appearance of what seems to be an additional row beneath the menu. This only appears in IE and not in Firefox.

Also, in Firefox, my Clearpixel.gif (spacer) images show up. Is this normal?

08-17-2005, 12:00 AM
Forms have margins and paddings.
Set them to 0 in the CSS.
IE "fixed" it for you when it was invalid. :cool:

Might fix that spacer image thing, too.
I didn't check, but you DO have a doctype with a URL in there, right? Not doing so sets off quirks mode, the biggest thing most likely to make pages behave differently cross-browser.

08-17-2005, 01:20 AM
I reverted to the original nesting of cells and forms which cured the IE problem of the extra row (although I think that it was actually a double height row). In doing so I found an extra <td> tag which may have been what was throwing up the invalid html.

All of my pages have doctype attributes but none of the php scripts that are called as includes nor the .js files have them.

Setting the height of the spacer images to 1 has disappeared them without any obvious effect on page layout.

I think I'll quit whilst I'm ahead and start working on the content for a while.

Once again, my most grateful thanks. I owe you a beer or two!!