How to Add drop down for custom pages

Started by suresh1983, April 24, 2014, 11:40:44 AM

Previous topic - Next topic

suresh1983

Dear all,

I tried pages mod and was successful in installing it and in creating pages.

Request you to kindly help me with the code for creating dropdown as mentioned below in the page with a button (Go).

In the drop down, I want to add page 1, page 2, page 3

When a specific page is selected in the drop down and when "go" button is used the user should be taken to that page.

I used the code as mentioned below but when the go button is clicked nothing happens  :(

<script>
function goToNewPage(dropdownlist)
{
var url = dropdownlist.options(dropdownlist.selectedIndex).value;
if (url != "")
{
window.open(url);
}
}
</script>
<form name="dropdown">
<label>Search <u>E</u>ngines</label>
<select name="list" accesskey="E">
<option selected>Please select one</option>
<option value="http://forum.officeadministration.info/index.php?action=page;id=1 [nofollow]">Page 1</option>
<option value="http://forum.officeadministration.info/index.php?action=page;id=1 [nofollow]">Page 2</option>
<option value="http://forum.officeadministration.info/index.php?action=page;id=1 [nofollow]">Page 3</option>
<option value="http://forum.officeadministration.info/index.php?action=page;id=1 [nofollow]">Page 4</option>
<select>
<input type=button value="Go" onclick="goToNewPage(document.dropdown.list)">
</form>

With regards,
Suresh.

Dragooon

<input type=button value="Go" onclick="goToNewPage(document.dropdown.list)">
should be
<input type=button value="Go" onclick="goToNewPage(document.forms.dropdown.list.value)">

function goToNewPage(dropdownlist)
{
var url = dropdownlist.options(dropdownlist.selectedIndex).value;
if (url != "")
{
window.open(url);
}
}

should be
function goToNewPage(url)
{
    if (typeof url != 'undefined' && url.length > 0)
        document.location = url;   
}


suresh1983

Hi,

As per your suggestion, I tried the same but it's not working...

when i click on "Go", there is no response  :( :(

This is the url of the site

http://forum.officeadministration.info/index.php?action=page;id=2


Dragooon

This is your HTML
<div style="padding: 2ex;" id="helpmain" class="windowbg2">Test page content<br /><br />test page content<br /><br /><a href="http://forum.officeadministration.info/index.php?PHPSESSID=09c143e880e6284542fc4a401dacaac3&amp;action=page;id=1">Click here to view another page</a><br /><br /><script><br /><br />function goToNewPage(url)<br />{<br />&nbsp; &nbsp; if (typeof url != 'undefined' && url.length > 0)<br />&nbsp; &nbsp; &nbsp; &nbsp; document.location = url; &nbsp; &nbsp;<br />}<br /></script><br /><form name="dropdown"><br />&nbsp;<label>Search <u>E</u>ngines</label><br />&nbsp;<select name="list" accesskey="E"><br />&nbsp;<option selected>Please select one</option><br />&nbsp;<option value="http://search.msn.com/">MSN Search</option><br />&nbsp;<option value="http://www.google.com/">Google Google</option><br />&nbsp;<option value="http://www.search.com/">Search.com</option><br />&nbsp;<option value="http://www.dogpile.com/">Dogpile</option><br />&nbsp;<select><br /><input type=button value="Go"onclick="goToNewPage(document.forms.dropdown.list.value)"><br /></form></div>

Your JS isn't being inserted correctly.

suresh1983

Hi,

I tried using <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">

but it didn't work.

request you to kindly direct me towards the correct code :)

suresh1983

Hi,

Please help with the below issue. I tried various options but none of them worked....

emanuele

The code Dragooon wrote is correct, but is converted by "something" in a form that doesn't work.

So the question is: how are you modifying the code? (I mean where do you type the code in? An editor and then with ftp you load the file? From a form in the admin panel?)


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

suresh1983

Dear Emanuele,

I am entering the code directly in the page that I have created using "pages mod"

Dragooon

You should check with the mod author to make sure the mod can display proper HTML content.

emanuele

Can you post the link to where you downloaded the pages mod?


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.


emanuele

Two options:
1) when you create/edit the page remove the tick from "Enable BBCode". Of course that way you won't be able to use bbcode, up to you,
2) write the whole javascript on a single line like this:
<script>function goToNewPage(url){    if (typeof url != 'undefined' && url.length > 0)        document.location = url;    }</script>
Of course this solution is acceptable when the javascript is short like in that case, but it will become messy with longer javascript code.


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

suresh1983

Hi,

Thank you for the code that you have shared, when clicked on the "go" link it works but I am unable to figure out why it is taking me to the home page of the forum and not to the page for which is assigned to.

This dropdown is added in the page (http://forum.officeadministration.info/index.php?action=page;id=2)

For instance, in the below code I have mentioned that page 1 should go to a new page created by my which has id 1

Page 2 to a page which has id 3

but when "go" link is clicked it takes to the home page of the forum.

<script>function goToNewPage(url){    if (typeof url != 'undefined' && url.length > 0)        document.location = url;    }</script>

<form name="dropdown">
<label>Search <u>E</u>ngines</label>
<select name="list" accesskey="E">
<option selected>Please select one</option>
<option value="http://forum.officeadministration.info/index.php?action=page;id=1 [nofollow]">Page 1</option>
<option value="http://forum.officeadministration.info/index.php?action=page;id=1[nofollow]">Page 2</option>
<option value="http://forum.officeadministration.info/index.php?action=page;id=3 [nofollow]">Page 3</option>
<option value="http://forum.officeadministration.info/index.php?action=page;id=3 [nofollow]">Page 4</option>
<select>
<input type=button value="Go" onclick="goToNewPage(document.forms.dropdown.list.value)">
</form>

emanuele

Actually the second option (the one you picked) doesn't work for me.
Unless I disable bbcode, it doesn't work at all.

Anyway: here on my computer works just fine, but I have no idea about your page because it's accessible only to registered users.


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Advertisement: