I’m trying to submit data to a database and can only do it from certain HTML elements, not things like Divs, paragraph elements, etc. So I’ve tried:
-Copying paragraph element content to a textbox, which includes the code with it, making it look not so aesthetically pleasing.
-Tried a hidden input type on the recommendation of others, and what I saw after some googling, however; this just passed the same html code along with the link and submitted the same as a textbox, which I kind of expected, though I was told that the hidden input type would solve the problem, I’m not sure how it would since it just seems to be an invisible textbox.
-I’ve tried using the below variables to pass the link to the textbox without the visible HTML included in it, and although it passess the text without the HTML, of course the link doesn’t work, it’s just plain text from the link, but not an actual link.
So that brings me to, is there a way to copy and paste a LINK from one element to a textbox? I looked around online but didn’t see anything.
–
function copyText() {
var output = document.getElementById("paragraphitems").innerHTML;
var regex = /(<([^>]+)>)/ig
var result = output.replace(regex, "");
document.getElementById("TextBox1").value = result;
document.getElementById("TextBox2").value = result;
document.getElementById("contentsent").value = result;
}
[/QUOTE]
[code=html]<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>find/display link</title>
</head>
<body>
<div id="div1">lorem ipsum <a href="http://www.google.com">Google</a>.<br>
lorem ipsum <a href="http://www.bing.com">Bing</a>.</div>
<button onclick="copyText(div1,result)">click</button><br><br>
<textarea id="result"></textarea>
<script>
function copyText(el,r) {
var f = el.querySelectorAll('a');
for(var i = 0; i < f.length; i++){
var txt = f[i].textContent,
lnk = f[i].href;
r.value += '<a href="' + lnk + '">' + txt + '</a> ';
}
}
</script>
</body>
</html>[/code]
This may be a cross-post but it's also a continuation of [B]this thread [/B].
So this started out as (paraphrased) "I need to copy the contents of a DIV into an input to be inserted in my database."
OK, fine, here's some example code.
"But I don't want any HTML to be included"
OK, fine, here's some example code.
"Well, it's an RSS feed"
OK, fine, research blah blah.
Now it's:
"I need to pull a link from a DIV"
OK, fine, here's some example code.
The OP really needs to provide answers to the following:
What really needs to be submitted to the database?
What will OP do with that data?
Why does this need to occur client-side and not server-side?
Look, a "link" consists of 2 things:
1) A set of <a>nchor tags with a [B]href[/B] attribute containing the URL and/or target of the link.
2) Text or another element (<img> for example) contained within the <a></a> tagset.
Without either of those you don't have a "link". So what do you want???[/QUOTE]
My page is pulling an RSS feed and displaying it in a <div> (<p>, whatever...). I need to find all the links, grab the URLs of those links, put them in a form input and send them to my database. I cannot do this server-side so this needs to be a client-side solution.[/quote]
txt = f[i].textContent,
r.value += '<a href="' + lnk + '">' + txt + '</a> ';
r.value += lnk + ' ';
[code=html]<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>find/display link</title>
</head>
<body>
<div id="div1">lorem ipsum <a href="http://www.google.com">Google</a>.<br>
lorem ipsum <a href="http://www.bing.com">Bing</a>.</div>
<button onclick="copyText(div1,result)">click</button><br><br>
<textarea id="result"></textarea>
<script>
function copyText(el,r) {
var f = el.querySelectorAll('a');
for(var i = 0; i < f.length; i++){
var lnk = f[i].href;
r.value += lnk + ' ';
}
}
</script>
</body>
</html>[/code]
[CODE]<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>find/display link</title>
</head>
<body>
<div id="div1">lorem ipsum <a href="http://www.google.com">Google</a>.<br>
lorem ipsum <a href="http://www.bing.com">Bing</a>.</div>
<button onclick="copyText(div1,result)">click</button><br><br>
<textarea id="result"></textarea>
<textarea id="result2"></textarea>
<script>
function copyText(el,result) {
var f = el.querySelectorAll('a');
for(var i = 0; i < f.length; i++){
var txt = f[i].textContent;
var lnk = f[i].href;
result.value += lnk + ' ';
result2.value += txt + ' ';
}
}
</script>
</body>
</html>[/CODE]
[CODE]<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>find/display link</title>
</head>
<body>
<div id="div1">lorem ipsum <a href="http://www.google.com">Google</a>.<br>
lorem ipsum <a href="http://www.bing.com">Bing</a>.</div>
<button onclick="copyText(div1,result)">click</button><br><br>
<textarea id="result"></textarea>
<script>
function copyText(el,r) {
var f = el.querySelectorAll('a');
for(var i = 0; i < f.length; i++){
var txt = f[i].textContent,
lnk = f[i].href;
r.value += '<a href="' + lnk + '">' + txt + '</a> ';
}
}
</script>
</body>
</html>[/CODE]
0.1.9 — BETA 5.29