Results 1 to 9 of 9

Thread: concatenate string

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    75

    concatenate string

    Hi,

    i add a textbox and
    i add an href that go like this:

    <a href="http://www.google.co.il/search?q= target=_main"> click here </a>


    no when the user click the link, i want it to go the address that in the href when the string in the text box concatenate after the ?q=
    for example if the user wrote ski so the string go like this:
    http://www.google.co.il/search?q=ski

    how can i do that
    thanks a lot

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: concatenate string

    You would need to use Javascript to do this. Use the onclick event to intercept the mouse click and modify the element:
    HTML Code:
    <html>
        <body>
    <script type="text/javascript">
    function anchorClick(element)
    {
        var txtBox = document.getElementById('concat');
        
        element.setAttribute('href', element.getAttribute('href') + txtBox.value);
    
    }
    </script>
    <a href="http://www.google.co.il/search?q=" onclick="anchorClick(this)" target="_main"> click here </a>
    <input type="text" id="concat" />
    
        </body>
    </html>
    Notice the use of the id attribute for the text box. This is important as it allows you to refer to the element in the javascript code.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    75

    Re: concatenate string

    it's work but when i click the link again it concatenate to the last string that was in the textbox.
    for example if one time the user wrote ski and in the secend time the user wrote soccer. the secend time string will be skisoccer.

    how can i get only the present string and not concatenate past string.

    thanks a lot

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: concatenate string

    Sorry about that, I've changed it so it uses a regular expression. The replace functions simply searchfor a q= in the string and replacesit with the text form the text box:
    HTML Code:
    <html>
        <body>
    <script type="text/javascript">
    function anchorClick(element)
    {
        var txtBox = document.getElementById('concat');
        var regExp = /q=.*/;
        var href = element.getAttribute('href');
    
        href = href.replace(regExp, 'q=' +  txtBox.value);
        
        element.setAttribute('href', href);
    
    }
    </script>
    <a href="http://www.google.co.il/search?q=" onclick="anchorClick(this)" target="_main"> click here </a>
    <input type="text" id="concat" />
    
        </body>
    </html>
    Last edited by visualAd; Aug 15th, 2005 at 12:43 AM.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    75

    Re: concatenate string

    it doesnt work

    the first code work but keep the last string befor. the update code doesnt work. it's not move to any URL

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: concatenate string

    Have you changed the target to _main?? I chnged it to _blank to it would work for me
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    75

    Re: concatenate string

    of course.
    i kept it on _main

  8. #8
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: concatenate string

    I'm not sure why it doesn't work for you. I have tested this in Internet Explorer and Firefox. What browser are you using and what version. Also, turn on error notifications for Javascript and see if you get any errors.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    75

    Re: concatenate string

    ohh it's work

    thanks a lot

Posting Permissions

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



Click Here to Expand Forum to Full Width