Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Add url to textfield

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #26704
    asp
    Participant

    Hi

    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. ;)

    #66452
    Hugo
    Member

    Can you show some code?

    #66453
    asp
    Participant

    This 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

    #66646
    BaylorRae
    Member

    This effect is easy with jQuery.

    Here’s a working example
    http://jsbin.com/uvuve3

    And you can see the code here
    http://jsbin.com/uvuve3/edit

    I’ve added a few comments to the jQuery, but if you want me to explain in more detail just ask. ;)

    #66658
    asp
    Participant

    Nice :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. ;)

    #66664
    BaylorRae
    Member

    Okay, here’s an update.

    // View the demo
    http://jsbin.com/unose

    // View the demo’s code
    http://jsbin.com/unose/edit

    I only changed two things.
    1.) The button now has the attribute ‘value’ (e.g. value="http://some-url.com&quot;)
    2.) jQuery now looks for the attribute ‘value’ in the button clicked

    The PHP to create the buttons for links will look like this

    Code:
    ‘ . $row[‘title’] . ‘‘;

    }

    ?>

    #66689
    asp
    Participant

    Nice :D

    Thank you, I got it to work.

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.