Welcome to WebmasterWorld Guest from 174.129.96.175

Forum Moderators: open

how to format this correctly

   
1:08 pm on Oct 22, 2009 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Hi everyone, I have a bit of code that I have been using for years, I need to add some new vars to it, heres the code

function formSubmit(formName){
var start_year = document.search.start_year.value;
var start_month = document.search.start_month.value;
var start_day = document.search.start_day.value;
var duration = document.search.duration.value;

var targetresult="date_search_results.php?start_year="+start_year;
window.open(targetresult, 'none', 'scrollbars=1,width=590,height=520');
}

I want to add the month, day and duration to the targetresult bit, have tried a few ways but not sure why it keeps erroring, obviousley where I am putting "" in is incorrect

1:44 pm on Oct 22, 2009 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month




var targetresult = "date_search_results.php?" +
"start_year=" + encodeURIComponent(start_year) +
"&start_month=" + encodeURIComponent(start_month) +
"&start_day=" + encodeURIComponent(start_day) +
"&duration=" + encodeURIComponent(duration);
1:52 pm on Oct 22, 2009 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Thanks Fotiman, I was missing the extra +
2:01 pm on Oct 22, 2009 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Actually, I don't think you need to escape the ampersand since you're not writing it to the document, so should have been this:


var targetresult = "date_search_results.php?" +
"start_year=" + encodeURIComponent(start_year) +
"&start_month=" + encodeURIComponent(start_month) +
"&start_day=" + encodeURIComponent(start_day) +
"&duration=" + encodeURIComponent(duration);

Hope that helps.

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month