从下拉变量确定的超链接

时间:2013-12-28 22:51:25

标签: javascript variables hyperlink

任何人都可以帮助我,我需要更改以下代码,以便从下拉菜单中选择一个场地将添加到超链接www.mydomain / +(来自下拉列表的变量).html,以便超链接适合于下拉选择。谢谢

     </li>
     <li class="form-line" id="id_7">
    <label class="form-label-left" id="label_7" for="input_7">
      Choose the venue you are Booking for<span class="form-required">*</span>
    </label>
    <div id="cid_7" class="form-input">
      <select class="form-dropdown validate[required]" style="width:150px" id="input_7" name="q7_chooseThe">
        <option value="Please select">Please select </option>
        <option value="Kirkcaldy"> Kirkcaldy </option>
        <option value="Hawick"> Hawick </option>
        <option value="Carlisle"> Carlisle </option>
        <option value="Inverkeithing"> Inverkeithing </option>
        <option value="Alva"> Alva </option>
        <option value="Keith"> Keith </option>
        <option value="Nairn"> Nairn </option>
        <option value="Aboyne"> Aboyne </option>
      </select> 
   </div>
   <div>
          <input id="input_16" class="form-hidden widget-required form-widget" type="hidden" name="q16_clickTo16" value="">
    </div>
        <script>
        document.getElementById("customFieldFrame_16").src = "http://widgets.jotform.io/termsConditions/?termsText=I%20have%20read%20the%20%7Bconditions%20of%20let%7D.&termsLink=www.mydomain.org + (variable from dropdown).html&marginLeft=150px&qid=16&ref=" + encodeURIComponent("http://") + document.location.host;

var _JCFClientID = 16             

1 个答案:

答案 0 :(得分:0)

假设您的hyperlink位于页面的某个位置,我们会给它一个虚构的ID #spot

使用此Javascript:

addEvent(document.getElementById('input_7'), 'change', function (evt) {
    var e = evt || window.event,
        input = (e.currentTarget) ? e.currentTarget : e.srcElement;
    document.getElementById('spot').setAttribute('href', 'http://www.mydomain.com/' + input.value + '.html');
});

function addEvent(element, myEvent, fnc) {
    return ((element.attachEvent) ? element.attachEvent('on' + myEvent, fnc) : element.addEventListener(myEvent, fnc, false));
}

而且你已经全部准备好了。在我的演示文稿中更改href中的选项时,请观看Chrome检查器中的<select>

Visual Stimulation for your enjoyment :)