• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

type a url and press the button to go on that page

 
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<!DOCTYPE html>
<html>
<head>
<script>
function newDoc() {

window.location.href =
}
</script>
</head>
<body>
URL: <input type="text" name="URL" value="">
<input type="button" value="Enter" onclick="newDoc()">

</body>
</html>
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you know how to get an element by ID in JavaScript? That will let you get the value.
 
ekte spiriopoulos
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:Do you know how to get an element by ID in JavaScript? That will let you get the value.

i should use it inside function?
 
Saloon Keeper
Posts: 15484
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you should locate the text field from within the function, get the value from the element and then reassign the window location.
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This isn't right:
document.getElementsByTagName("option")[x].value

Hint: You want to get the element by id. (which means you need to add an id)
 
ekte spiriopoulos
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:This isn't right:
document.getElementsByTagName("option")[x].value

Hint: You want to get the element by id. (which means you need to add an id)

i try this

window.location.href (document.getElementsById.x);

i try this : window.location.href (document.getElementsById.value); but nothing

and this window.location.href (document.getElementsById); i still did nothing i cant find it
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You still don't have the write syntax. Try doing a console.log of your expression to get the value so you can see that you are getting a JavaScript syntax error there.
 
ekte spiriopoulos
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:You still don't have the write syntax. Try doing a console.log of your expression to get the value so you can see that you are getting a JavaScript syntax error there.


window.location.href (x =document.getElementsById);
after i try this window.location.href (element =document.getElementsById); but nothing .. :/
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Randomly trying different things with the wrong syntax isn't going to get you anywhere fast. You need to step back and learn the basic syntax of JavaScript before trying to write code like this.
 
ekte spiriopoulos
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Randomly trying different things with the wrong syntax isn't going to get you anywhere fast. You need to step back and learn the basic syntax of JavaScript before trying to write code like this.

ok.In this case how should have been writen?
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What website or article are you using to learn about JavaScript? If none, what did you Google to try to find one?

We want to help you learn. That isn't going to come from handing you the syntax.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A forum is not the place to learn basic language syntax. I'd find an introductory book or tutorial and learn how to write basic JavaScript statements, including how to make function calls.
 
ekte spiriopoulos
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:What website or article are you using to learn about JavaScript? If none, what did you Google to try to find one?

We want to help you learn. That isn't going to come from handing you the syntax.

you tell me that i have a wrong sentence i have try everything i have look everywhere but nothing .i can make a link to another page but i want to be the link given by user .I havent find nothing to related by this.I am learning from w3school.I dont know what basic needs windows.location or what i am doing wrong.Only this is a question you can tell me and i will learn it .Easy it is i beleive .It isnt something so confused .My mind is not working .I have done many exercices from morning so. I stuck here .If not give me answer its ok if yes you will get me out of a work from hour
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Forget about window.location for a minute. This is not right:
(x =document.getElementsById

That's not related to the problem you are trying to solve. It is basic JavaScript. Which page on w3schools taught you to write that code? I agree with Bear that you need a basic JavaScript tutorial. You won't learn it from copy/pasting code that I write.

If the problem is that you are tired and your "mind isn't working", the best thing to do is to step away from the problem and come back to it later (or Monday.)

 
ekte spiriopoulos
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:Forget about window.location for a minute. This is not right:
(x =document.getElementsById

That's not related to the problem you are trying to solve. It is basic JavaScript. Which page on w3schools taught you to write that code? I agree with Bear that you need a basic JavaScript tutorial. You won't learn it from copy/pasting code that I write.

If the problem is that you are tired and your "mind isn't working", the best thing to do is to step away from the problem and come back to it later (or Monday.)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 2</title>
<script>
var myWindow;

function OpenURL()
{
var address = document.getElementById("URL").value;
***code here ****
myWindow = window.location( address, "_blank", parameters );

}
function CloseWindow()
{
myWindow.close();
}

</script>

</head>

<body>
<span>Give a URL address:</span><input id="URL" type="text" size="60"/>

<input id="OpenURL" type="button" value="Open" onclick="OpenURL()"/>
<input id="Close" type="button" value="Close" onclick="CloseWindow()"/>
</body>

</html>

what else needs this?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic