Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14

Thread: Enter and Paste

  1. #1
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    149
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Enter and Paste

    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

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    149
    Thanks
    2
    Thanked 0 Times in 0 Posts
    korn,

    Yes. Autofill the input with value of link.

    thanks

    lebron

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    149
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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?

  • #6
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    149
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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

  • #7
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Sorry to be so insistent. It is not a problem of English, but one of the terms' precision
    Quote Originally Posted by lebronletchev View Post
    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
    Code:
    <!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>
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • Users who have thanked Kor for this post:

    lebronletchev (08-24-2007)

  • #8
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,387
    Thanks
    32
    Thanked 288 Times in 282 Posts
    Quote Originally Posted by lebronletchev View Post
    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.

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

    Code:
    <!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>
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #9
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    149
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Arbitrator,

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

    Lebron

  • #10
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    149
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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

  • #11
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,387
    Thanks
    32
    Thanked 288 Times in 282 Posts
    Quote Originally Posted by lebronletchev View Post
    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]

    1. http://en.wikipedia.org/wiki/List_of...ity_references
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #12
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    149
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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

  • #13
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    149
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Ok. Now i understood... but I saved the document as charset=iso-8859-1
    and now it is working fine!

    thanks

    Lebron

  • #14
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,387
    Thanks
    32
    Thanked 288 Times in 282 Posts
    Quote Originally Posted by lebronletchev View Post
    Sorry by my file it is not a html file. It is as .ASP file
    I’ve no idea what the difference is since I don’t know ASP.

    Quote Originally Posted by lebronletchev View Post
    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.
    For every complex problem, there is an answer that is clear, simple, and wrong.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •