SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Skills to Pay the Bills Sparkie's Avatar
    Join Date
    Jul 1999
    Location
    A cave with 47 computers and an internet feed
    Posts
    3,559
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Enter Your First Name Prompt

    One of my clients would like to have a script that lets someone enter their first name and then it pre-populates parts of the sales letter below with their name. I know there's a Javascript prompt that will do this but I was hoping maybe there was a more user-friendly way to go about this?

    What is the code I would need?
    Sherice Jacob - Web Improvement Expert
    Improve Website Conversions | eBook Covers
    Follow Me on Twitter!

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yeah, javascript prompts are definitely not the way to go.

    If it has to be client-side, it'd still be fairly simple. Just create a text input box, which, onkeyup, would change the sales letter below it.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    Skills to Pay the Bills Sparkie's Avatar
    Join Date
    Jul 1999
    Location
    A cave with 47 computers and an internet feed
    Posts
    3,559
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know how to do that... I'm a designer rather than a programmer
    Sherice Jacob - Web Improvement Expert
    Improve Website Conversions | eBook Covers
    Follow Me on Twitter!

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2008
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's a rough example. I'm not sure it works cross-browser, but it works under Firefox 3.

    Code:
    <html>
    <body>
    
    <script>
    var baseText = "Hey FirstName, check out Product1, Product2.";
    
    function changeText(){
    	var theName = document.getElementById("firstNameField").value;
    	document.getElementById("theText").innerHTML = baseText.replace("FirstName", theName);
    }
    </script>
    
    <input type="text" value="John" id="firstNameField">
    <input type="button" value="click" onclick="changeText()">
    
    <div id="theText">(text will go here)</div>
    
    </body></html>

  5. #5
    Skills to Pay the Bills Sparkie's Avatar
    Join Date
    Jul 1999
    Location
    A cave with 47 computers and an internet feed
    Posts
    3,559
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks !! I'll give it a try and see how it goes
    Sherice Jacob - Web Improvement Expert
    Improve Website Conversions | eBook Covers
    Follow Me on Twitter!

  6. #6
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,880
    Mentioned
    48 Post(s)
    Tagged
    0 Thread(s)
    That will work, but for only the 1st occurance.

    "Hi {firstName}, how are you" will become:

    "Hi Sparkie, how are you".

    But if you have more that 1 occurance of {firstName} it will only replace the 1st one.

    To replace all of them you will need to do this:

    baseText.replace(/FirstName/g, theName);


Tags for this Thread

Bookmarks

Posting Permissions

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