Click to See Complete Forum and Search --> : trying to return a value to <a href=""> tag


kyleabaker
05-07-2006, 04:49 PM
hey, i'm trying to make a widget for opera9 and i just realize that they disable javascript popup windows, and i'm using javascript to filter thru what a user is searching for and then in the javascript i have it return the value which is the full url it needs to follow. is there any way i can do something like this in the html...

<a href="javascript: search()"><img border="0" src="search.PNG" width="67" height="24"></a>

or

<a href=search()><img border="0" src="search.PNG" width="67" height="24"></a>

...cause search() should be returning the url. how can i plug that into the <a> tag?

Charles
05-07-2006, 04:53 PM
<a href="#" onclick="this.href = search()"><img border="0" src="search.PNG" width="67" height="24"></a>

kyleabaker
05-07-2006, 05:11 PM
thanx for the fast response, but i tried what you said and now it will open a new window, but it is directed to "index.html#" which is the same window. i think its just not replacing the # with the search() value or something.

Charles
05-07-2006, 05:15 PM
I'm not sure what your up to. My example should direct you to whatever is returned by search().

kyleabaker
05-07-2006, 05:18 PM
sorry, i'll post the js code below. maybe i messed up in it somewhere...

function search(){
s=new String(document.all.T1.value)
s.replace(" ","+")
if (document.all.D1.value==0){
//Searching Band Names
s="http://www.911tabs.com/search.php?search="+s+"&type=band"
}
else if (document.all.D1.value==1){
//Searching SOng Names
s="http://www.911tabs.com/search.php?search="+s+"&type=song"
}
return s
}

...should it be... function String search(){ ...etc?

sorry, i'm new to javascript, coming to javascript from java ;)

Charles
05-07-2006, 05:29 PM
JavaScript is not in the least like Java. This is one case where what you already know will be a hunderance. JavaScript is loosly typed.

felgall
05-07-2006, 06:09 PM
document.all doesn't work for all browsers - you should be using document.getElementById()

phpnovice
05-07-2006, 06:20 PM
...unless D1 and T1 are the names of form elements -- in which case you should be using something more like the following syntax:

document.forms["formName"].elements["elementName"].value

Charles
05-07-2006, 06:25 PM
document.all doesn't work for all browsers - you should be using document.getElementById()JavaScript itself doesn't work for all browsers. document.write is fine for HTML, but not for XHTML, and is a great deal better than assigning to HTMLElement.innerHTML.

kyleabaker
05-07-2006, 07:23 PM
well, i 'm making a widget for opera9, so the only browser i'm testing it with is opera9.

you all are right tho, the T1 is a text box, but its not it a form at all, just by itself. the D1 is a dropdown box where the user picks to search for band or song name.

that all aside, i did try Charles gave me in the beginning in I.E. and Opera, but it simply navigated the browser to the same page with "#" appended to the end of it.

i thru in an alert(s) right before the return and the s string is generated correctly. i'm just having problems inbetween the return and the <a href="#" onclick="this.href = search()"> tag.

i appreciate everyone helping tho!

kyleabaker
05-07-2006, 07:59 PM
i thru the widget in my web folder. just go here and you can see what i'm working on and take a look at the code if you like. please, if you get a chance, check it out and let me know what problems i am having with it. It's my first opera widget, so its not a big deal, but i want to finish it, haha. thanx all you javascript gurus!

oh yeah, just to let you know, i can't use a normal javascript popup window because opera disables javascript popups from widgets. thats why i'm trying this way.

thanx again

http://152.7.44.52/911tabs/

Logician
05-07-2006, 09:10 PM
hey, i'm trying to make a widget for opera9 and i just realize that they disable javascript popup windows, and i'm using javascript to filter thru what a user is searching for and then in the javascript i have it return the value which is the full url it needs to follow. is there any way i can do something like this in the html...

<a href="javascript: search()"><img border="0" src="search.PNG" width="67" height="24"></a>

or

<a href=search()><img border="0" src="search.PNG" width="67" height="24"></a>

...cause search() should be returning the url. how can i plug that into the <a> tag?

I can't imagine why you're calling it an Opera widget, but never mind.

First of all, for internal reasons you cannot name your function 'search'.
I suggest that the text box and select are placed within form tags.

This example assumes that such a form is called 'f1' :


<SCRIPT type='text/javascript'>


function bandSearch()
{
var f=document.forms['f1'];

var s=f.T1.value;

s=s.replace(" ","+");

if(f.D1.value==0)
{
//Searching Band Names
s="http://www.911tabs.com/search.php?search="+s+"&type=band"
}
else
if (f.D1.value==1)
{
//Searching SOng Names
s="http://www.911tabs.com/search.php?search="+s+"&type=song"
}


return s;

}

</SCRIPT>

<a href='#' onclick="this.href=bandSearch()">SEARCH</A>

phpnovice
05-07-2006, 09:14 PM
the T1 is a text box, but its not it a form at all, just by itself. the D1 is a dropdown box where the user picks to search for band or song name.
form elements are required to be in a form. They cannot exist alone. You also need a DOCTYPE in your page. And, this:

<SCRIPT src="commands.js"></SCRIPT>

should be more like this:

<SCRIPT src="commands.js" type="text/javascript"></SCRIPT>

etc. Take your url to validator.w3.org (http://validator.w3.org/) so that you can at least be working with valid HTML.

kyleabaker
05-07-2006, 10:21 PM
@Logician
Is that sarcastic? The new Opera Beta version 9 allows the user to use widgets made only for Opera... => Opera Widgets. If you are unfamiliar then just to breifly explain, these widgets are small web applications, anything that a browser can render and run _only_ in opera, not konfabulator or yahoo as it is today.

Sorry my html is messy, but I am using Front Page 2003. Also, why should it matter that the form items are not in a form? i am not manipulating a form, I am only checking values of the textbox and the drop down box.

I can fix the html to match w3 standards, but why must it be in a form? I mean, i'm not doubting you guys at all, i just don't understand how that would make them function differently.

@phpnovice
when you say they cannot exist alone, do you mean shouldn't exist alone according to standards or what? cause once again i'm not doubting you, just wondering why they work fine for me.

i'm glad you guys know your stuff, haha, this web environment is still very new to me! i'm used to win32 applications, whole different ball game, lol.
thanx

phpnovice
05-07-2006, 10:50 PM
Sorry my html is messy, but I am using Front Page 2003.
hehehe, don't blame it on the tool. One should never depend upon a tool to do everything for them. Any tool, misused, will do the wrong thing. That is not to say that you are necessarily (i.e., knowingly) doing something wrong or that FrontPage will always do everything correctly if you use it correctly. Hey, I use FrontPage, too. So I know that, if FrontPage is set up properly, it will not let you add a form element to the page without also creating the form object. But, it will also let you remove the form object after the fact -- leaving the form element standing alone. ;)
Also, why should it matter that the form items are not in a form? i am not manipulating a form, I am only checking values of the textbox and the drop down box.
You cannot properly check the values of a form element if there is no form object in place. There's only one thing wrong with getting in the habit of being content just because something works in one particular instance. The same habit will come back to bite you in other circumstances.
when you say they cannot exist alone, do you mean shouldn't exist alone according to standards or what? ... just wondering why they work fine for me.
It is according to standards, but it is not *just* about standards. As I said, you cannot properly reference a form element with JavaScript if there is no form object in place. You may find other ways to reference a form element that is standing alone, but those ways will not work in all cases. Some browsers won't even render a form element that is not in a form. There's nothing more frustrating than ending up with a page that won't work when you're sitting there beating your head against the wall and decrying, "But it always worked before!"

kyleabaker
05-07-2006, 10:54 PM
ok, i understand the standards. you are correct about the form, but i didn't see how that was incorrect until you explained, ;)

back to the javascript problem tho...will fixing the form and the elements inside cause the javascript function to work properly? is that what is stopping it from working?

phpnovice
05-07-2006, 11:05 PM
will fixing the form and the elements inside cause the javascript function to work properly? is that what is stopping it from working?
That is a safe bet -- but not a guarantee. Thus, I'd start with the (seemingly) obvious (fix the form) and see what else might drop out.

kyleabaker
05-07-2006, 11:26 PM
did you take a look at the javascript? does it look ok (other than having to change the calls to the form elements)?

EDIT:
@Logician
thanx! the problem I was experiencing was with the search() function name. I changed it to tabSearch and changed the call for it in the <a> tag and it all works now!

@phpnovice
i'm in the process of cleaning the code up ;)
for the record, the convincing part of your argument is that in the future it might not work properly if it doesn't follow the standards. ;) good argument, haha. even tho this isn't all that important i'd hate to see it get outdated in no time, lol.

@all
thanks so much for your help guys! this site is great, the fastest help i've ever experienced!

cheers

Charles
05-08-2006, 05:26 AM
There is no requirement that form controls be contained by a FORM element but there is a requirement that every FORM element contain an action attribute. So if the controls are there simply at the service of some script and the form itself will not be submitted it is best to omit the FORM element. You will not be able to address the controls through the form then but other methods exist. Perhaps the easiest is to give each control and ID and use document.getElemenetById.

Unless there is somethng specific to Opera Widgets there is no reason to not name your function "sort".

phpnovice
05-08-2006, 10:33 AM
There is no requirement that form controls be contained by a FORM element...
I've seen both NS and FF not render form elements in the absence of a form object. What's with that?

kyleabaker
05-08-2006, 10:38 AM
first of all, NS sucks, secondly...well i don't know about the second one, FF is ok in my opinion, renders most everything i've tested it with, opera is by far my fav tho because of its lite weight and custimizations.

i'm going ahead and working on the form tho anyways, won't hurt anything to throw it in there just so theres less chance of it breaking down later on.

Charles
05-08-2006, 11:12 AM
I've seen both NS and FF not render form elements in the absence of a form object. What's with that?Perhaps you were using an early, buggy version. But the DTD is clear and a form control are just another inline element.

phpnovice
05-08-2006, 12:10 PM
OK, I sure wish somebody'd make up my mind. Just a year or two ago, I was told, on this site (I won't bother to mention names, as they just claim I'm mistaken), that all INPUTs, SELECT, and TEXTAREA had to be inside a FORM. Only the BUTTON tag could be used outside a FORM. I've spent all this time getting creative with non-submitable FORM tags for nothing? :rolleyes: Sheesh!

kyleabaker
05-08-2006, 12:22 PM
lol, it probably actually helped you out in the long run ;)

i never thought it mattered if they were in forms but it can help when keeping pages neat and code clean. but if you're not submitting anything then the form is pointless.

Charles
05-08-2006, 12:40 PM
OK, I sure wish somebody'd make up my mind. Just a year or two ago, I was told, on this site (I won't bother to mention names, as they just claim I'm mistaken), that all INPUTs, SELECT, and TEXTAREA had to be inside a FORM. Only the BUTTON tag could be used outside a FORM. I've spent all this time getting creative with non-submitable FORM tags for nothing? :rolleyes: Sheesh!Don't believe anything you read on the internet about HTML unless it's found at http://www.w3.org/TR/REC-html40/ .

phpnovice
05-08-2006, 01:09 PM
... unless it's found at ...
Problem is, they (and a lot of other entities) don't know how to create documentation that lends itself as efficient researchable material. All of the W3C and ECMA material I've found requires too much painstaking (and pointless) reading just to find a small iota of pertinent information. It is also incomplete (NJMHO) -- meaning, you can't find everything you want to know about a single element when looking up (and at) just that element. :rolleyes:

You want to kill MS IE? Create better documentation -- and you might just have a shot. You say other browsers do it better? Maybe -- but they are almost totally undocumented for DHTML use as far as I am concerned. I'd be happy to program first for any other browser, that is supposedly truer to the standards, when I can find documentation like the following for such a browser:

MS DHTML Objects (http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects.asp)
MS JScript Reference (http://msdn.microsoft.com/library/en-us/script56/html/1e9b3876-3d38-4fd8-8596-1bbfe2330aa9.asp)

kyleabaker
05-08-2006, 01:16 PM
http://my.opera.com/community/dev/web/

The first advantage of Opera is that it is and always has been committed to standards support. This makes pages that work with Opera likely to work with any other browser, and in particular it will make your pages "future compliant".

slaughters
05-08-2006, 02:23 PM
http://my.opera.com/community/dev/web/
If you ignore the whole point of this thread. You know the, "... widgets made only for Opera... => Opera Widgets." :)

kyleabaker
05-08-2006, 11:56 PM
"... widgets made only for Opera... => Opera Widgets." :)

exactly!