Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
help on window.location Options
Old 05-06-2007, 11:05 PM help on window.location Options
Skilled Talker

Posts: 70
Name: rex
Trades: 0
hi,


i do have dropdown box that contains several items with attached
links:

<select class="text" onchange="linker()" name="menu1">
<option value="#" selected="selected">--- Countries
---</option>
<option
value="#">Argentina</option>
<option value="#">Australia</option>
<option value="#">Brazil</option>
<option value="#">Canada</option>
<option value="#">China</option>
<option value="http://
www.mypage.com"class="textRed">*France</option>

the linker() function:

function linker(){
var s=menu1.options[menu1.selectedIndex].value;
if(s !== '#'){
window.location.href = s;
}

this works perfectly IE but in doesnt work in firefox. can someone pls
tell me what is wrong?
tnx
shotokan99 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-07-2007, 01:37 AM Re: help on window.location Options
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
Code:
if (s != '#') {
 
}
You've got one equals sign too many in your code.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 05-07-2007, 05:23 AM Re: help on window.location Options
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
I'm surprised that worked in IE, but they seem pretty confident about guessing at what people mean in code.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 05-07-2007, 06:35 AM Re: help on window.location Options
Skilled Talker

Posts: 70
Name: rex
Trades: 0
i tried to make it:

if(s!= '#').. still not working in ie...
shotokan99 is offline
Reply With Quote
View Public Profile
 
Old 05-07-2007, 11:29 AM Re: help on window.location Options
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
IE doesn't work or Firefox? You said Firefox originally.

At any rate, there are additional errors:

var s=menu1.options[menu1.selectedIndex].value;

You need to include the name of the form twice here. Something like:

var s=document.YourFormNameHere.menu1.options[document.YourFormNameHere.menu1.selectedIndex].value;

Also, you're missing an end bracket from your function. }

The spacing in your code may be causing issues as well. Put all of your <option>s on one line so that there are no carriage returns; I doubt that's causing your problem but it's good form.

If those don't solve it, then you'll have to post the error message you're getting. Type javascript: into your address bar in Firefox to see it.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 05-08-2007, 11:04 PM Re: help on window.location Options
Skilled Talker

Posts: 70
Name: rex
Trades: 0
using my old function:
function linker(){
var s=menu1.options[menu1.selectedIndex].value;
if(s != '#'){
window.location.href = s;
}
when run in firefox, i type "javascript:" on the address bar and i got the following msgs:
*Warning: Error in parsing value for property 'font-weight'. Declaration dropped.
Source File: http://www.mysite.com/styles.css
Line: 492
*Warning: Error in parsing value for property 'text-decoration'. Declaration dropped.
Source File: http://www.mysite.com/styles.css
Line: 580
*Error: menu1 is not defined
Source File: http://www.mysite.com/index.php
Line: 30
@adam:
since my dropdown box is not inside the form so i omitted the form name instead
done it this way:
function linker(){
var s=document.menu1.options[document.menu1.selectedIndex].value;
if(s != '#'){
window.location.href = s;
}
}
this time i got the ff msgS:
*Error: document.menu1 has no properties
Source File: http://www.mysite.com/index.php
Line: 31
*Warning: Error in parsing value for property 'font-weight'. Declaration dropped.
Source File: http://www.mysite.com/styles.css
Line: 492
*Warning: Error in parsing value for property 'text-decoration'. Declaration dropped.
Source File: http://www.mysite.com/styles.css
Line: 580
shotokan99 is offline
Reply With Quote
View Public Profile
 
Old 05-09-2007, 12:16 AM Re: help on window.location Options
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
That would probably do it.

Try this instead:

<select class="text" onchange="linker()" id="menu1">

And for linker, do this:

var menuField = document.getElementById("menu1");
var s = menuField.options[menuField.selectedIndex].value;

This should do it.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 05-09-2007, 02:24 PM Re: help on window.location Options
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Try setting the id value, not just the name value:
HTML Code:
<select class="text" onchange="linker()" name="menu1" id="menu1"> 
As for the CSS errors, it's probably that you're using an IE-specific command or you have a typo in the declaration - check your stylesheet for the respective lines.

OOPS. I didn't see ADAM's response (I've blocked him for some rude behavior). Sorry about the overlap.

As for his comment, however, you need to have both the name and id values if the form will be submitted to the server.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE

Last edited by JeremyMiller; 05-09-2007 at 02:25 PM..
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 05-14-2007, 10:35 PM Re: help on window.location Options
Skilled Talker

Posts: 70
Name: rex
Trades: 0
tnx guys it did the trick..just a very simple question. what is the difference between "name" and "id"? for instance with $_POST['..'] it is taking what the id or the name?
shotokan99 is offline
Reply With Quote
View Public Profile
 
Old 05-15-2007, 12:37 AM Re: help on window.location Options
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
$_POST holds name's, not id's. name is for the form. id is for the DOM. (Very simplified, but enough for most uses.)
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 05-15-2007, 04:59 AM Re: help on window.location Options
Skilled Talker

Posts: 70
Name: rex
Trades: 0
for instance i do have this element but i dont have a <form>:
<input type="Text" name="myname" id="myname" size="30"...>

then i have this link:
echo'<a href="mypage.php?name='.$myname.'...>Save</a>';

i want that $myname will the value of myname textbox. something like this:
$myname= <the value of the textbox>

then on the sideo mypage.php it will catch the values on same manner:
$myname=$_GET['myname'];
.
.
.


i know this can be easily using <form>...</form>. but just for the sake of discussion is this possible? incase it is, how get the value of the textbox and assign it to $myname variable?
shotokan99 is offline
Reply With Quote
View Public Profile
 
Old 05-15-2007, 11:03 PM Re: help on window.location Options
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
It sounds like you're asking how to get the value of a variable in PHP which was not submitted in a form. Is that correct?
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 05-16-2007, 04:57 AM Re: help on window.location Options
Skilled Talker

Posts: 70
Name: rex
Trades: 0
...let me try to explain it clearly.
usually if we have this:

<form name=".." method="post" action="my.php">
<input type="Text" name="myname" id="myname" size="30"...> <Br>
<input type="submit" name".." value="save">
</form>

and my.php will have:

<?php
$myname=$_POST['myname'];
.
//processing here....
.
?>

now how about if i remove the <form...> tag. then instead of a submit
button ill replace it with a text linking to my.php. it loots
something like this:

<input type="Text" name="myname" id="myname" size="30"...> <Br>
<a href="my.php?name='.$myname.'...>Save</a>

then my.php will look like this:
<?phpa
$myname=$_GET['myname'];
.
//processing here....
.
?>
my problem is how get the value of the textbox and assign it to
$myname variable.
is it possible with php or i need javascript for this matter? i hope i
was able to explain it clearly
shotokan99 is offline
Reply With Quote
View Public Profile
 
Old 05-16-2007, 12:14 PM Re: help on window.location Options
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
You can't do what you want without javascript. PHP works only on the server, not in the browser. Javascript works only in the browser, not on the server. They are 2 totally different technologies for totally different uses (but, work well together).
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Reply     « Reply to help on window.location Options
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.39820 seconds with 12 queries