473,387 Members | 1,891 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,387 software developers and data experts.

making this js work in firefox?

I have this IE compliant JS code, but it refuses to work in firefox. What's
up with it?
I am not any good in JS and I don't have a lcue on how to debug it apart
from alert-s, so I kinda don't even know hwere to start :(
I am using it for my browser custom start page, js is enabled...


function doSearch(url,qname)
{
url += ( url.indexOf("?") > 0 )?"&":"?";
url += qname + "=" + document.getElementById("q").value;
if ( document.getElementById("chkNewWindow").checked )
window.open(url,'_blank','');
else
location.href = url;
}

form is like this

<form id="searchform" action="http://www.google.com/search?hl=en"
method="get">
Search query: <input type="text" id="q" name="q" maxlength="1000"
size="40">
<br /><input type="checkbox" name="chkNewWindow"> Open new window
</form>
<ul style=" text-indent: 20px;">
<li><a
href="javascript:doSearch('http://www.google.com/search?hl=en','search');">S
earch Google</a></li>
<li><a
href="javascript:doSearch('http://www.merriam-webster.com/cgi-bin/dictionary
?book=Dictionary','va');">Search Merriam-Webster</a></li>
<li><a
href="javascript:doSearch('http://www.technorati.com/cosmos/search.html?rank
=','url');">Search Technocrati</a></li>

etc
Jul 23 '05 #1
2 1358
Sergei Shelukhin wrote:
I have this IE compliant JS code, but it refuses to work in firefox. What's
up with it?
I am not any good in JS and I don't have a lcue on how to debug it apart
from alert-s, so I kinda don't even know hwere to start :(
I am using it for my browser custom start page, js is enabled...


function doSearch(url,qname)
{
url += ( url.indexOf("?") > 0 )?"&":"?";
url += qname + "=" + document.getElementById("q").value;
if ( document.getElementById("chkNewWindow").checked )
if (document.forms["searchform"].chkNewWindow.checked) {

Your checkbox has no "id" attribute.
Mick

window.open(url,'_blank','');
else
location.href = url;
}

form is like this

<form id="searchform" action="http://www.google.com/search?hl=en"
method="get">
Search query: <input type="text" id="q" name="q" maxlength="1000"
size="40">
<br /><input type="checkbox" name="chkNewWindow"> Open new window
</form>
<ul style=" text-indent: 20px;">
<li><a
href="javascript:doSearch('http://www.google.com/search?hl=en','search');">S
earch Google</a></li>
<li><a
href="javascript:doSearch('http://www.merriam-webster.com/cgi-bin/dictionary
?book=Dictionary','va');">Search Merriam-Webster</a></li>
<li><a
href="javascript:doSearch('http://www.technorati.com/cosmos/search.html?rank
=','url');">Search Technocrati</a></li>

etc

Jul 23 '05 #2
On Wed, 10 Nov 2004 00:57:03 +0300, Sergei Shelukhin
<ra******@home.domonet.ru> wrote:

[snip]
I am using it for my browser custom start page, js is enabled...
As in your own personal page?
function doSearch(url,qname)
{
url += ( url.indexOf("?") > 0 )?"&":"?";
url += qname + "=" + document.getElementById("q").value;
if ( document.getElementById("chkNewWindow").checked )
IE has a bug whereby document.getElementById will return a reference to an
element with a matching name attribute if no matching id can be found. It
should actually return null.

You don't need to use getElementById at all:

function doSearch(url, queryName) {
var elem = document.forms['searchform'].elements,
query = elem['q'].value,
newWin = elem['chkNewWindow'].checked;

url += ((-1 != url.indexOf('?')) ? '&' : '?')
+ queryName + '=' + query;

if(newWin) {window.open(url, '_blank');}
else {location.href = url;}
}

[snip]
<br /> [...]
Unless you're writing XHTML, just use "<br>".
<ul style=" text-indent: 20px;">
The left margin is probably what you want to adjust.
href="javascript:doSearch('http://www.google.com/search?hl=en','search');">


You shouldn't normally use the javascript: scheme, but as this is for your
own use, there isn't much harm.

[snip]

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3

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

Similar topics

2
by: Stewart | last post by:
Originally posted in comp.lang.javascript: Newsgroups: comp.lang.javascript From: "Stewart" Date: 23 Aug 2005 02:50:04 -0700 Local: Tues, Aug 23 2005 10:50 am Subject: FireFox, RemoveChild,...
21
by: PlainDave | last post by:
Hi, Is there a way to make windows tooltips stay up longer than the default 5 seconds using CSS in a web page? I'd prefer to have it stay visible as long as the mouse is over the "whatever." The...
19
by: Martin Eyles | last post by:
Hi, I want to make a whole table a link, so that clicking anywhere on it takes you to another page. Unfortunately the way I initially thought of doing this involved invalid html. I have tried a...
2
by: Nehmo | last post by:
On http://sketchup.google.com/gsu5vtviewer.html#id=27 The video for the Rotate Tool lesson works okay when I click on it, but I want to link directly to it. Looking at the source of the page...
3
by: Mufasa | last post by:
Can anybody suggest websites that talk about what you need to do to make an IE site also work under Firefox. What things are allowed and what aren't - that type of thing. TIA - Jeff.
7
by: Dr J R Stockton | last post by:
I want page <URL:http://www.merlyn.demon.co.uk/js-quick.htmto open, in IE6, IE7, Firefox 2, and wherever else practicable, with the control labelled F.X0 fully visible at the top of the window and...
6
by: frankenstein | last post by:
I've not seen any real sollutions to this yet. I found something similar on this forum but the posted sollutions didn't work. I would like to make a drag to scroll for my blog, using JS. So far I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.