How to pass variable to href in javascript?

前端 未结 5 1696
没有蜡笔的小新
没有蜡笔的小新 2021-01-04 09:24

How to pass this variable value here? Below code is not working. And all other discussions on Stackoverflow are unclear.



        
5条回答
  •  天命终不由人
    2021-01-04 09:27

    You have fetch value of the field, Currently you are using DOM object

    Use

     var dist = document.getElementById('value').value;
    

    OR

    Use

     if (dist.value!=""){
         window.location.href="district.php?dist="+dist.value;
    

    instead of

    if (dist!=""){
         window.location.href="district.php?dist="+dist;
    

提交回复
热议问题