...

View Full Version : Enter and Paste



lebronletchev
08-22-2007, 12:48 PM
Hi,

If i have the following text:



With violence unrelenting, <A HREF="album.html">political</A> pressure mounted for Prime Minister Nouri al-Maliki to show <A HREF="album.html">progress</A> in bringing Iraq's battling factions together.
and a form like this...


<form>
<input name="query" maxlength="255" style="width: 150px" id="searchbox" alt="Search" value="">
<input value="Search" type="submit" />
</form>


How I do for instead put manually a value in

<input name="query" maxlength="255" style="width: 150px" id="searchbox" alt="Search" value="">

put it automatically when I click (left mouse button) in one of the links of teh text? Showing the link values??

Thank you

lebron

Kor
08-22-2007, 12:55 PM
What you want to do when click on the links? Go to album.html only? autofill the input (by the way, you need a type="text") only? Both?

lebronletchev
08-22-2007, 01:29 PM
korn,

Yes. Autofill the input with value of link.

thanks

lebron

Kor
08-22-2007, 01:47 PM
Just a moment. It is a matter of actions. The moment you click on a link, you session is changed, so I see no reason to auto fill the text field, as long as the page looses its session and opens another web page...

Well, the link action can be prevent in javascript (with a return false), but then why to use a link as long as you will never go there?.... Seems confusing to me. can you detail what you intend to do?

Once again, what those link (<a href="album.html">..<a>) are there for?

lebronletchev
08-22-2007, 05:15 PM
Immagine a webpage with a lot of links... However in such script when the user click on a link open the following statement:


<form>
<input name="query" maxlength="255" style="width: 150px" id="searchbox" alt="Search" value="">
<input value="Search" type="submit" />
</form>

In other words WHEN THE USER CLICK ON A LINK INSTEAD OPEN A "WEBPAGE" OR OTHER LINK, THE USER OPEN A <FORM>. Ok?

Well, in this way the user would need write the "text" of the link. In our "political" and "progress". Ok?

In this way and using this bad written English I am looking for a function or statement in JS which would "paste" that text to the <FORM> when the user would click on a link. And the user simply would click "submit" and voilŠ the other link or web page will open!

Thank you again

Lebron



In this case the user have just the option to put

Just a moment. It is a matter of actions. The moment you click on a link, you session is changed, so I see no reason to auto fill the text field, as long as the page looses its session and opens another web page...

Well, the link action can be prevent in javascript (with a return false), but then why to use a link as long as you will never go there?.... Seems confusing to me. can you detail what you intend to do?

lebronletchev
08-23-2007, 11:03 AM
The dataselect of this page it is a good example I am looking for...

http://javascript.about.com/library/bldatesel1.htm

...but more simple


Thanks

lebron

Kor
08-23-2007, 01:28 PM
Sorry to be so insistent. It is not a problem of English, but one of the terms' precision

Immagine a webpage with a lot of links... However in such script when the user click on a link open the following statement:
In other words WHEN THE USER CLICK ON A LINK INSTEAD OPEN A "WEBPAGE" OR OTHER LINK, THE USER OPEN A <FORM>. Ok?

No, it is not ok. What do you mean by "open a form" ?

Anyway, even I still don't understand what happens on your page, here's my approximation


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
/*<![CDATA[*/
function autofill(obj){
document.getElementById('searchbox').value=obj.firstChild.nodeValue;
}
/*]]>*/
</script>
</head>
<body>
<div>With violence unrelenting, <a href="#" onclick="autofill(this);return false">political</a> pressure mounted for Prime Minister Nouri al-Maliki to show <a href="#" onclick="autofill(this);return false">progress</a> in bringing Iraq's battling factions together.</div>
<br />
<form>
<input name="query" maxlength="255" style="width: 150px" id="searchbox" alt="Search" value="">
<input value="Search" type="submit" />
</form>
</body>
</html>

Arbitrator
08-23-2007, 03:15 PM
How I do for instead put manually a value in

[Ö]

put it automatically when I click (left mouse button) in one of the links of teh text? Showing the link values??Hereís another take. [1] Compared to Korís solution, it doesnít use inline scripting, is valid and conforming HTML, and doesnít use filler values for the href attribute. I didnít bother putting together a full form.

I took this as a chance to experiment with textContent and innerText.


http://www.jsgp.us/demos/cf121994.html


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!-- saved from url=(0025)http://www.jsgp.us/demos/ -->

<html lang="en-Latn">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Demo for CodingForums.com Thread 121994</title>
<meta name="Author" content="Patrick Garies">
<meta name="Created" content="2007-08-23">
<meta name="Revised" content="2007-08-23">
<style type="text/css" media="all">
* { margin: 0; padding: 0; }
html, input { background: white; color: black; font: 16px/1.2 sans-serif; }
p, div { margin: 1em; }
.term { color: green; text-decoration: underline; cursor: pointer; }
cite { font-style: normal; }
div { text-align: center; }
label::after { content: ":"; }
input { width: 15em; padding: 0.1em 0.2em; }
#scripts { display: none; }
</style>
<!--[if IE]>
<style type="text/css" media="all">
label { content: expression(this.innerText.substring(this.innerText.length - 1, this.innerText.length) == ":" ? null : this.innerText = this.innerText + ":"); }
</style>
<![endif]-->

</head>
<body>

<p>With violence unrelenting, <a class="term">political</a> pressure mounted for <a class="term"><cite>Prime Minister Nouri al-Maliki</cite></a> to show <a class="term">progress</a> in bringing <a class="term"><cite>Iraq</cite></a>ís battling factions together.</p>
<div>
<label for="term">Term</label>
<input id="term" type="text">
</div>

<div id="scripts">
<!--[if !IE]>-->
<script type="application/ecmascript">
var d = document;
var di = d.implementation;
if (di.hasFeature("MouseEvents", "2.0") && di.hasFeature("HTML", "2.0") && d.documentElement.textContent) {
var anchors = d.getElementsByTagName("a");
for (var i = 0; i < anchors.length; i++) {
if (anchors[i].hasAttribute("class") && anchors[i].getAttribute("class").match(/(^| )term( |$)/)) {
anchors[i].addEventListener("click", function () {
d.getElementById("term").value = this.textContent;
}, false);
}
}
}
</script>
<!--<![endif]-->
<!--[if IE]>
<script type="text/javascript">
var d = document;
var anchors = d.getElementsByTagName("a");
for (var i = 0; i < anchors.length; i++) {
if (anchors[i].className && anchors[i].className.match(/(^| )term( |$)/)) {
anchors[i].attachEvent("onclick", (function (i) {
return function () {
d.getElementById("term").value = anchors[i].innerText;
};
})(i));
}
}
</script>
<![endif]-->
</div>

</body>
</html>

lebronletchev
08-24-2007, 10:29 AM
Arbitrator,

Well... Works very fine! Thank you for your helpful!

Lebron

lebronletchev
08-28-2007, 09:10 AM
Arbitrator,

Your script works fine. Very fine, especiallyw tih English Texts. I know there is a way to "include" in the code "characters with accent", but I donīt remember where I put this information, especially for Spanish and german texts.

Thank you again

Arbitrator
08-28-2007, 04:10 PM
I know there is a way to "include" in the code "characters with accent", but I donīt remember where I put this information, especially for Spanish and german texts.Save the document as UTF‐8 and input the characters directly or use character references. [1]


http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

lebronletchev
08-29-2007, 09:12 AM
Arbitrator,

Sorry by my file it is not a html file. It is as .ASP file

I think I would need add special characters in this code line:


match(/(^| )term( |$)/))

Thanks

Lebron

lebronletchev
08-29-2007, 09:40 AM
Ok. Now i understood... but I saved the document as charset=iso-8859-1
and now it is working fine!

thanks

Lebron

Arbitrator
08-29-2007, 06:24 PM
Sorry by my file it is not a html file. It is as .ASP fileIíve no idea what the difference is since I donít know ASP.


I think I would need add special characters in this code line:I know that you solved the problem, but, for future reference, Iíll provide an example demonstrating how to escape characters using ECMAScript (JavaScript) syntax:


To escape the No‐Break Space character, you could use \u00a0. The character code is in hexadecimal. I believe that you could also use \xa0 and \U000000a0, although Iíve never actually used either of those. The former would be convenient for codes with only two significant characters while the latter would be necessary for those rare codes that require more than four significant characters.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum