Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>See this demo: <a href="http://jsfiddle.net/JFqrH/3/" rel="nofollow">http://jsfiddle.net/JFqrH/3/</a></p> <p>HTML:</p> <pre><code>&lt;form&gt; &lt;p&gt; &lt;select id = "list" name = "list" onchange ='output(this);' &gt; &lt;option&gt;&lt;/option&gt; &lt;option&gt;link1&lt;/option&gt; &lt;option&gt;link2&lt;/option&gt; &lt;option&gt;link3&lt;/option&gt; &lt;option&gt;link4&lt;/option&gt; &lt;option&gt;link5&lt;/option&gt; &lt;/select&gt; &lt;/p&gt; &lt;a id="url" href="/web/sso/bw/ostrfer.jsp"&gt;/web/sso/bw/ostrfer.jsp&lt;/a&gt; &lt;a id="url1" href="/web/sso/bw/ostrfer.jsp"&gt;/web/sso/bw/ostrfer1.jsp&lt;/a&gt; &lt;a id="url2" href="/web/sso/bw/ostrfer.jsp"&gt;/web/sso/bw/ostrfer2.jsp&lt;/a&gt; &lt;/form&gt;​ </code></pre> <p>JS:</p> <pre><code>function output (choice) { var index = choice.selectedIndex; var prefix = ""; if(index == 1) prefix = "https://link1"; else if (index == 2) prefix = "https://link2"; else if (index == 3) prefix = "https://link3"; else if (index == 4) prefix = "https://link4"; else if (index == 5) prefix = "https://link5"; updateLink(document.getElementById("url"), prefix); updateLink(document.getElementById("url1"), prefix); updateLink(document.getElementById("url2"), prefix); }​ function updateLink(url, prefix) { if(!url.getAttribute("postfix")) {// need to save orignal href as it will be replaced later url.setAttribute("postfix", url.getAttribute("href")); } var postfix = url.getAttribute("postfix"); url.innerHTML = prefix + postfix; url.href = prefix + postfix; } </code></pre> <p>You have multiple syntax errors in your code. Plus <code>a href=&lt;span id = "url"&gt;&lt;/span&gt;</code> is nonsence. It can't work. Instead of that you should use attributes (see <a href="https://developer.mozilla.org/en-US/docs/DOM/element.getAttribute" rel="nofollow">getAttribute</a>/<a href="https://developer.mozilla.org/en-US/docs/DOM/element.setAttribute" rel="nofollow">setAttribute</a>). Also, it is much simpler to use swithc statement instead of if/else. Another thing: <code>onchange=output(this.form.liste);</code> - instead of this you can use <code>onchange=output(this);</code> as this will already point to your dropdown element there. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload