Forum Moderators: open

Message Too Old, No Replies

write to a textarea in another frame onclick

         

illtron

3:10 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



OK, this seems like something that javascript is capable of, but I barely ever use it, so I'm not really sure on how to go about doing it.

I have a frameset (It's a good use of them, I swear), with two rows, and the bottom row has two columns, for a total of three frames. This sums it up, I think:

----------------------
¦ top ¦
----------------------
¦ ¦ ¦
¦ ¦ ¦
¦ ¦ ¦
¦ list ¦ pages ¦
¦ ¦ ¦
¦ ¦ ¦
¦ ¦ ¦
¦ ¦ ¦
----------------------

"list" is a list of links, but they're generated from a fairly crappy custom CMS, so I have no control over the formatting of the actual links.

I have the target set for that frame to be the frame "pages."

In "top," I have a textarea. Firefox has a nice behavior where if I drag a link from pages to the textarea in top, it puts the URL of the link on one line, and the text of the link on the next. IE doesn't even let me drag the links. Typical.

This works ok, but I'd like to have the URL show up in that textarea when I click it.

Is this possible?

As a bonus, would it be possible to have the text of the link go up there too, like what happens when I drag the link in Firefox?

As an even bigger bonus, would it be possible to strip part of the URL out? Instead of [blahblahblah.com...] could I just have /whatever/something/this.html show up?

Am I asking too much?

illtron

3:15 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



My little illustration didn't make it, so if I didn't explain it well, please let me know. The style codes won't seem to let me include all those spaces.

SpaceFrog

3:38 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



parent.top.document.textareaname.value='blabla'

bonus

mystring="http://www.blahblahblah.com/whatever/something/this.html"
alert(mystring.split(".com")[1])

illtron

5:08 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



That's a big rough. Could you possibly spell it out a bit more and help me with the script?

albo

7:33 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



If you really want to get persnickety about it you could descend the form element tree (parent.framename.document.formname.text-area-field-name.value=newvalue...
I used to have a three-frame site and this worked.

albo

8:24 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



instead of "name" I mean "id" where html shows id="some-id"; javascript descends via getElementsBy... mechanisms of various sorts; you could use document.forms[n] (forms[0] if it is the only form on the document) to descend to the textarea in your javascript) then find the textarea elements[n]
parent.framename.document.form[n].element[n].value=

illtron

1:38 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



Could you possibly walk me through this a little more? Javascript is all sort of Greek to me. I can usually integrate a script, but I'm not really able to get started with writing it. I'm not really sure where to start. I've tried to give as much detail as I can, but please let me know if more will be helpful.

SpaceFrog

2:28 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



I would personnaly not name top frame as top ... as this is a reserved word of javascript language

let's say you have got three frames

<html>
<head>
<title>Nouvelle page 1</title>

</head>

<frameset rows="64,*">
<frame name="banner" scrolling="no" noresize>
<frameset cols="468,*">
<frame name="menu" src="nouvellepage2.htm">
<frame name="principal" src="nouvellepage3.htm">
</frameset>
<noframes>
I swear it is good usage of frames
</noframes>
</frameset>
</html>
[code]

for example you could access an input in principal from menu by a link in nouvellpage2.htm as follows:
<a [code]onclick="parent.principal.document.getElementById('myinput').value='hello'">fsdf</a>

with an input in nouvellepage3.htm:
<input type='text' id='myinput' />

illtron

4:48 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



OK, I'm definitely making some progress!

I've got a test link with this code...

<a href="page.html" onclick="parent.topframe.document.getElementById('thebox').value=href+' '+' '+'Good, it works'">Test link</a>

This gives me this result when I click it...


http://www.theurlofthepage.com/thepage.html Good, it works

This is a great start, I think.

Next, is it possible to apply this to the whole page (or at least in certain parts of the page) without having to edit every actual link? I ask because I have no control over the formatting and code of the actual links, due to them being generated by a crappy content management system. Can I have this apply to links in a div or the whole document?

Also, how about having it write the actual link text?

And last, how do I tell javascript to put the second part on another line? I can't just tell it to write a line break, because that'll write that in the text area, right?

You're a huge help so far guys!

illtron

6:15 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



You can skip the part about the second line. That was sort of simple. I already knew how to to that. The rest is still on the table, however

illtron

6:31 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



OK, another update...

I'm working with this simple script...


<script language="JavaScript"><!--
function functionName(text) {
}
//--></script>

And this is my link:

<a href="page.html" onclick="parent.topframe.document.getElementById('thebox').value=href+'\r'+this.text">Another test link</a>

It gives me this result in Firefox:

[whatever.com...]
Another test link

Firefox does it right. In IE, the second line just comes up as undefined. Is there an error that I'm missing? It's not a huge deal since 99% of the time, I'll be the only person who will using this particular page.

The real issue I'm now faced with is getting every link on the page to do this by default. How could I do that?

albo

10:10 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



sAnother way might be to have (1)
<a href="javascript:routine(parameters...)">

function routine(...) { ...
target-var-array=parent.targetframe.documument.getElementsByTagName('text'); for (i=0; i<target-var-array.length; i++) { j=target-var-array[i]; if (j.id=='myinput') { j.value='mynewvalue'; break; } /* end of loop */; } /* end of function */; }

!be careful of case on getElementsByTagName or other such functions...I used the name routine above, you'll change it, of course!

albo

10:15 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



oops typo getElementsByTagname('input')