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.

Coding Forum


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



Reply
Old 08-26-2004, 02:15 AM Javascript Help
Extreme Talker

Posts: 170
Location: Canada
Trades: 0
How do i make the content (a number value in this case) write into another part of the javascript?

example:
Code:
window.open('http://www.mywebsite.com/picture_##.gif')
where it says ## is where I want the forms value to write should it be something more like:

Code:
window.open('http://www.mywebsite.com/picture_'+'##'+'.gif')
collyer_1 is offline
Reply With Quote
View Public Profile Visit collyer_1's homepage!
 
 
Register now for full access!
Old 08-26-2004, 02:42 AM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
What kind of "forms value"? To get the value from an input box, for example, is easy. To get it from a drop down takes a bit more code.

Here's how you'd get it from an input box, replacing 'myform' and 'mytextbox' with the names of your form and input box.

Code:
num = document.myform.mytextbox.value;
window.open('http://www.mywebsite.com/picture_' + num + '.gif')
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
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

Christopher is offline
Reply With Quote
View Public Profile
 
Old 08-26-2004, 12:47 PM Still in the gutter
Extreme Talker

Posts: 170
Location: Canada
Trades: 0
The code you gave me looks like it should work, but for some reason it doesn't. Here is the page (modified slightly) so you can see it.

HTML Code:
<html>
<body>

<SCRIPT LANGUAGE="javascript">

num = document.input.number.value;
function load()
{ window.open('http://www.MYWEBSITE.com/PICTURE_'+ num +'.gif'); }

</SCRIPT>

<form id="input">
<input id="number" type="text" size=6>
<input type="button" value="Submit" onClick="load()">
</form>

</body>
</html>
collyer_1 is offline
Reply With Quote
View Public Profile Visit collyer_1's homepage!
 
Old 08-26-2004, 01:10 PM
JohnS's Avatar
Skilled Talker

Posts: 89
Location: London, UK
Trades: 0
Case sensitive image names? Are your images named 'picture' or 'PICTURE'? Something simple that always seems to get me! Not too good with javascript, but that looks as though it should work correctly to me?
JohnS is offline
Reply With Quote
View Public Profile Visit JohnS's homepage!
 
Old 08-26-2004, 01:36 PM
Extreme Talker

Posts: 170
Location: Canada
Trades: 0
no, case sensitive is not the issue...

Whenever I run the script the address comes out: www.mywebsite.com/picture_undefined.gif

so somewhere in the script it's failing and I don't know why
collyer_1 is offline
Reply With Quote
View Public Profile Visit collyer_1's homepage!
 
Old 08-26-2004, 01:37 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
Code:
<html>
<head>
    <script language="javascript">
    
    function load()
    {
        num = document.input.number.value;
        window.open('http://www.MYWEBSITE.com/PICTURE_'+ num +'.gif');
    }
    </script>
</head>
<body>

<form name="input">
<input name="number" type="text" size=6>
<input type="button" value="Submit" onClick="load()">
</form>

</body>
</html>
Two things, one is to use "name", not "id" and the second is to get the value 'num' inside of the function. The way you have it, 'num' will always be a nothing because as soon as the page loads it get's the value then.
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
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

Christopher is offline
Reply With Quote
View Public Profile
 
Old 08-26-2004, 01:47 PM But Wait there's more!
Extreme Talker

Posts: 170
Location: Canada
Trades: 0
Thanks alot Chroder it finally works. I'll also remember this:

Quote:
Originally Posted by Chroder
Two things, one is to use "name", not "id" and the second is to get the value 'num' inside of the function. The way you have it, 'num' will always be a nothing because as soon as the page loads it get's the value then.
----------------------------------------------------------------------------------

But wait there's more! Last night as I finally got the javascript working (thanks to much help from Chroder) I realizewd that I wanted the picture to open in a frame. I also realized that I havn't the faintest Idea how to make that work. Any thoughts?

Rundown:
The javascript (discussed above) is opened in the top frame (frame name= "top") when the javascript is executed i want the picture to open in the bottom frame (named= "body").

Last edited by collyer_1; 08-27-2004 at 01:11 PM..
collyer_1 is offline
Reply With Quote
View Public Profile Visit collyer_1's homepage!
 
Reply     « Reply to Javascript Help
 

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.62079 seconds with 12 queries