javascript - How to manually set an href with value from variables in jquery -


i using datepicker , each day, month , year being saved in variable, afterwards print in structure want.

here jquery:

jquery(document).ready( function($){     alert('alert function');     var txtfromdate, txttodate;   $("#txtfrom").datepicker({     numberofmonths: 1,     onselect: function(selected) {       txtfromdate = selected;       var dt = new date(selected);       dt.setdate(dt.getdate() + 1);       $("#txtto").datepicker("option", "mindate", dt);     }   });   $("#txtto").datepicker({     numberofmonths: 1,     onselect: function(selected) {       txttodate = selected;       var dt = new date(selected);       dt.setdate(dt.getdate() - 1);       $("#txtfrom").datepicker("option", "maxdate", dt);     }   });    $('.submit-here').click(function() {     // var link = day_1+month_1+year;     var date1 = $("#txtfrom").datepicker('getdate'),         day_1  = date1.getdate(),           month_1 = date1.getmonth() + 1,                       year_1 =  date1.getfullyear();      var date2 = $("#txtto").datepicker('getdate'),         day_2  = date2.getdate(),           month_2 = date2.getmonth() + 1,                       year_2 =  date2.getfullyear();       var = $('#selection :selected').text();     var people = $('#people :selected').text();      console.log('www.lekkeslaap.co.za/akkommodasie-in/'+where+'?q='+where+'&start='+day_1+'+'+month_1+'+'+year_1+'&end='+day_2+'+'+month_2+'+'+year_2+'&pax='+people);    });    }); 

the entire code in snippet

how can manually set values of href values variables have when click on button?

i tried this:

$("a#atributo").attr("href", "www.lekkeslaap.co.za/akkommodasie-in/'+where+'?q='+where+'&start='+day_1+'+'+month_1+'+'+year_1+'&end='+day_2+'+'+month_2+'+'+year_2+'&pax='+people") 

but when click on link looks attr not reading values variables normal text instead.

i testing in this site?

make sure beginning , end of strings open/closed matching quotemark.

if start string double quotes, end doubles quotes. same applies single quotes.

your string assignment didn't work because tried close string opened double quotes single quote.

consider following code:

$("a#atributo").attr("href",    "www.lekkeslaap.co.za/akkommodasie-in/"   +where+   "?q="+where+   "&start="+day_1+ "+" +month_1+ "+" +year_1+   '&end=' +day_2+ '+' + month_2+ '+' +year_2+   '&pax='+people); 

each individual string literal opened , closed matching quotes. it's useful decide create strings 1 of two, , keep consistent it.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -