Apply onclick function only if text entered??

M

Mike Weathery

Hi all

I am using the following function in a text entry box:

function goToTV() {
location.href="http://www.tvguide.com" + "/search/index.aspx?keyword=" +
document.search.q.value;
return false;
}

E.g. if the user types in "Lost" then clicks 'TV', it sends them to the URL:
http://www.tvguide.com/search/index.aspx?keyword=Lost

However sometimes I want people to just be able to click TV without typing a
search keyword, but this causes problems as the target site does not
understand
http://www.tvguide.com/search/index.aspx?keyword=

In that case I want it just to go to
http://www.tvguide.com


Q: Is there a way to make the js only apply the '+
"/search/index.aspx?keyword=" + document.search.q.value;' part if there is
text entered in q?

E.g. location.href="http://www.tvguide.com" + ONLY IF Q CONTAINS TEXT THEN
ADD "/search/index.aspx?keyword=" + document.search.q.value;

Thanks in advance for any simple mod to my above js that can do this.

M.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,144
Latest member
KetoBaseReviews
Top