473,378 Members | 1,426 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Apply onclick function only if text entered??

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.
Nov 21 '06 #1
3 2744
try like this:
function goToTV() {
if (document.search.q.value != "")
{
location.href="http://www.tvguide.com" +
"/search/index.aspx?keyword=" +
document.search.q.value;
}
else
{
location.href="http://www.tvguide.com" ;
}
return false;

}

On Nov 22, 7:41 am, "Mike Weathery" <a...@anon.comwrote:
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
understandhttp://www.tvguide.com/search/index.aspx?keyword=

In that case I want it just to go tohttp://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.
Nov 21 '06 #2
Worked a treat! Thanks so much!
M.

<jh*****@gmail.comwrote in message
news:11**********************@j44g2000cwa.googlegr oups.com...
try like this:
function goToTV() {
if (document.search.q.value != "")
{
location.href="http://www.tvguide.com" +
"/search/index.aspx?keyword=" +
document.search.q.value;
}
else
{
location.href="http://www.tvguide.com" ;
}
return false;

}

On Nov 22, 7:41 am, "Mike Weathery" <a...@anon.comwrote:
>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
understandhttp://www.tvguide.com/search/index.aspx?keyword=

In that case I want it just to go tohttp://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.

Nov 21 '06 #3
ASM
Mike Weathery a écrit :
Hi all
Hi you
I am using the following function in a text entry box:
function goToTV() {
var loc = document.search.q.value;
loc = loc!=''? "/search/index.aspx?keyword="+loc : '/';
location.href="http://www.tvguide.com" + loc;
return false; // this last not useful
}

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Nov 22 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jez | last post by:
Hi, I've created a function which opens a popup window containing a calendar. When a day is clicked, the date is entered into a text box on the parent page and the popup is closed. The link...
2
by: Kevin Lyons | last post by:
Hello, Can anyone assist me with what I am trying to do with the following code (six different scenarios to try to make the functionality work correctly)? I want to always (and ONLY) display...
2
by: RobG | last post by:
I am trying to dynamically add an onclick to an element, however I just can't get the syntax right. consider the following function: function doClick (evt,x) { // do things with evt and x } ...
9
by: Marco Krechting | last post by:
Hi All, I have a page with a list of hyperlinks. I want to save information in a cookie about the fact that I entered an hyperlink or not. When I click one of the hyperlinks I want this stored...
2
by: Heiko Vainsalu | last post by:
Hi Hope somebody knows how to solve this one. *The Situation* A traditional situation where HTML form inputs are checked... (if simplified then it would look something like this) <form...
1
by: ramalingam | last post by:
Hi I am very new to PHP. Please help. I have a HTML code in a php file which takes in USERID and password. I have <input name="Submit" type="button" value="Submit" onClick="funCheck()"/>,...
2
by: bay_dar | last post by:
Hi, I have an internal ASP.NET application that I'm are using to send e-mails out based on a single milepost or milepost range entered. I'm trying to do two things when a user clicks on the...
2
by: iwasjoeking | last post by:
Hi all, I am trying to make it so that the style "RowSelected" (embedded below) is applied to the table row from which the radio button is selected, and then removed when a different radio...
13
by: Mtek | last post by:
Hi, We have a form defined with buttons like this: <a class="save_menu" href="javascript:document.Detail_Screen.action = 'savedata.php?screen=EDIT';document.Detail_Screen.submit();">Update</...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.