PDA

View Full Version : Returning values to a textfield...


arik00
10-02-2002, 01:47 PM
Hi, i'm new to this forum :o
and i'm a newbie when it comes to JavaScript...

and i have a question which is, i guess pretty advanced...

I have a page in which, there is a button which opens a window...
with some urls written in it, i was wondering.. is it possible that if a user clicks on a link... (in that opened window), the window will return the value... to the page, that originally opened that window...? i want to make this kinda browse button, that will open a new window show some files on the server... and return the file I chose... (the url)... to that page as it's value e.g. <input type="text" value="someurltaken from the window">.
update it's value some how...

is this even possible?

Thanks in advance
Arik

whackaxe
10-02-2002, 02:36 PM
yup thats possible and i would even say a piece pof pie!
what you need to understand is how to acces the openers root. try this on your page that has been opened

<script>
function changepage(theurl)
{
opener.window.location.href = theurl
window.close()
}
</script>

you just have to call the function when the users clicks the button with the url as an argument. what the opener.window does is send you to the root of the winodws parent window and then you can change what you like

arik00
10-02-2002, 03:07 PM
First i open a window right... ok i add an on click event to the urls...

use your function to write to the root window... (the one that opened the window)
write the changes i want and close the window..?

i'll add a mini question here:

how to change the value of a textfield?
e.g. <input type="text" value="changethis">

Thanks in advance
(thank you for your reply whackaxe)

Arik

arik00
10-02-2002, 04:27 PM
Anyone?

adios
10-02-2002, 05:01 PM
Someone.


<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="javascript">

var kid = null;
var HTML = '<html><head><title>The Kid</title></head>';
HTML += '<body onblur="setTimeout(\\'self.focus()\\',100)">';
HTML += '<a href="http://www.codingforums.com" ';
HTML += 'onclick="opener.document.forms[0].readout.value=this.href">';
HTML += 'coding forums</a><br>';
HTML += '<a href="http://www.google.com" ';
HTML += 'onclick="opener.document.forms[0].readout.value=this.href">';
HTML += 'google</a></body></html>';

function openit() {
kid = open('javascript:opener.HTML','kid',
'width=400,height=200,left=200,top=200,status=0');
kid.focus();
}

</script>
</head>
<body>
<form>
<input type="text" name="readout" size="30">
<input type="button" value="OPEN" onclick="openit()">
</form>
</body>
</html>

arik00
10-02-2002, 06:15 PM
Now one last thing...
How do i close the kid window? :p

Thanks a lot anyway!!!

Arik :thumbsup:

adios
10-02-2002, 11:42 PM
Click on that little x in the upper-right-hand corner. :D

OK, OK....

if (kid && !kid.closed) kid.close();


shalom, adios

whammy
10-03-2002, 02:18 AM
In English:

"Easy as pie"

"Piece of cake"

;)