0

I have a small issue. I created a select box on my index page, where users should be able to select a link to go to an external website. This external url should not open in another tab, but inside my project. The values in this select box are pulled out of a database dynamically (that works fine). The issue I am facing now is when I click on the link name inside the select box, the redirect fails and shows that that method does not exist in my controller.

My code so far in my index :

<label for="externallink" class="control-label">External Links</label>
  <select id="externallink" name="externallink" onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">
    <option value="0">-Select Link-</option>
  </select>

How it looks when I open the source of my page :

<select id="externallink" name="externallink"  class="form-control form-control-sm" onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);"><option value="">-Select Link-</option><option value="www.google.de">google</option><option value="www.youtube.com">Youtube</option></select>

Does anyone have an idea how to fix this, please ? Any help is much appreciated !

Kind regards

  • 1
    Please have a look at this: https://stackoverflow.com/questions/2000656/using-href-links-inside-option-tag – Salim Ibrohimi Apr 26 '20 at 16:51
  • I guess you must add **http://** or **https://** before url. – Raman Saluja Apr 26 '20 at 17:42
  • Hi all, thanks for the quick reply ! Well, if I add http:// in the link, it does work .. . However, the link opens external from my project. What I need is that it opens inside the project. I used google just as an example, the real url's I will add are related to my project, so they should open in it. – user12780319 Apr 26 '20 at 19:28

1 Answers1

2

Try including the protocol in the URL. For example https://google.com

Ivan Kirchev
  • 133
  • 1
  • 9
  • That works indeed. But, it opens in a new page. What I need is that it opens inside the project. Is there any way of obtaining this ? Tried things like adding target="_parent" or self in the form, but that does not have effect. – user12780319 Apr 27 '20 at 08:12
  • Oh, so you want to open a web page within a web page, right? For that you will have to use HTML Iframe. Here is some info on the topic https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe – Ivan Kirchev Apr 27 '20 at 09:44
  • I tried an example of iFrames, but it failed. The thing is that I have 2 select boxes, in a side bar. On the index page is a list of other data. The thing I want is that when you select an url (the other select box are hrefs) in those select boxes, it should "replace" my index page. The iFrames example I just tried gives an error in my index controller concerning the other data on my index page.. . – user12780319 Apr 27 '20 at 15:10
  • Ok, but If you want to display an external web page somewhere in your web page there is no other option but the Iframe, as far as I know. @user12780319 – Ivan Kirchev Apr 27 '20 at 15:24