Home › Forums › JavaScript › Add url to textfield
- This topic is empty.
-
AuthorPosts
-
November 8, 2009 at 3:04 pm #26704
asp
ParticipantHi
I’m making a sort of simple news system, but I’m stuck with a problem. I’m trying to add an image URL to a textfield when you click an image. But I can’t get it to work. I have tried to find any kind of plugin ore already fabricated code, but can’t find anything that works.
Do some of you know how to do this? I’ll be very happy if someone have the answer to the question. ;)
November 10, 2009 at 3:14 pm #66452Hugo
MemberCan you show some code?
November 10, 2009 at 3:45 pm #66453asp
ParticipantThis is how the php displays the URL’s that can be chosen. The point is that when the user clicks on the image the jquery adds the files_URL to a regular text box.
while($row = mysql_fetch_array($result))
{
echo ‘<div class="row" id="’ . $row .’">’;
echo ‘<h5>’ . $row . ‘ ‘ . $row . ‘ ‘ . $row . ‘ kb’;
echo ‘<a href="#"><img id="add" src="/Bilder/legg_til.png" /></a><a id="URL" href="/nyheter’ . $row . ‘">Prewiev</a></h5>’;
echo ‘</div>’;
}I also tryed to make somthing with jQuery
$(document).redy(function() {
var url = document.getElementById("URL").value;
$("#add").click( function() {
$("#textbox").append(url);
});
});This dident work 8-)
I also found somthing at the internet
function ChgText()
{
var MyElement = document.getElementById("MyTextBox");
MyElement.value = "If you see this, it worked!";return true;
}I got this to work, but not when trying to implement it with the php stuff.
I hope this helps :D
November 16, 2009 at 11:28 am #66646BaylorRae
MemberThis effect is easy with jQuery.
Here’s a working example
http://jsbin.com/uvuve3And you can see the code here
http://jsbin.com/uvuve3/editI’ve added a few comments to the jQuery, but if you want me to explain in more detail just ask. ;)
November 16, 2009 at 3:58 pm #66658asp
ParticipantNice :D
It seems to be what I’m looking for, but just to be on the safe side…This works with php to right?
My idea was to add a URL to the txtfield, but then I need to add the value of the URL. And if that is going to be the value of the button it will be quite long :? Ore am I missing somthing?
So is it possible to have a value of the button that says “add url” and then the button adds a url that the php generates.
The code you presented was brilliant but because I’m not that good with jquery I need some help from a pro. ;)
November 16, 2009 at 4:19 pm #66664BaylorRae
MemberOkay, here’s an update.
// View the demo
http://jsbin.com/unose// View the demo’s code
http://jsbin.com/unose/editI only changed two things.
1.) The button now has the attribute ‘value’ (e.g. value="http://some-url.com")
2.) jQuery now looks for the attribute ‘value’ in the button clickedThe PHP to create the buttons for links will look like this
Code:‘ . $row[‘title’] . ‘‘;}
?>
November 17, 2009 at 11:40 am #66689asp
ParticipantNice :D
Thank you, I got it to work.
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.