homepage Welcome to WebmasterWorld Guest from 54.145.183.169
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
how to format this correctly
wheelie34

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4011510 posted 1:08 pm on Oct 22, 2009 (gmt 0)

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

 

Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4011510 posted 1:44 pm on Oct 22, 2009 (gmt 0)


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

wheelie34

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4011510 posted 1:52 pm on Oct 22, 2009 (gmt 0)

Thanks Fotiman, I was missing the extra +

Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4011510 posted 2:01 pm on Oct 22, 2009 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved