Submit Form Replace Value with Custom Link

Discussion in 'JavaScript' started by musei, Aug 27, 2009.

  1. #1
    Hello Hello, I hope this makes sense (and I'm posting in the right forum section).

    Here's what I'm trying to do. I'm trying to type a form where the user will type in a 4 to 7 digit number:

    <input type="text" name="id" value="">
    <input type="submit" value="Submit">

    Cool so far. But what I need is after they submit it, the value that is put in there is submitted as a customized link (not http).

    Example: If a user inputs 1234, it will be changed to clink://1234@example.com


    So the question is, how do get it so that the value submitted from the form is inserted in between my clink:// and @example.com?

    Once again, hopefully that makes sense. I'm not even sure what I should be searching for on the forums. Maybe replace string or something? I don't know and I apologize.

    Any help would be greatly appreciated!

    --Musei
     
    musei, Aug 27, 2009 IP
  2. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #2
    <input type="text" name="id" id="clid" value="">
    <input type="submit" id="clsubmit" value="Submit">
    ...
    <script type="text/javascript">
    window.onload = function() {
        document.getElementById("clsubmit").onclick = function() {
            var clid = document.getElementById("clid"), newValue = "clink://" + clid.value + "@example.com";
            clid.value = newValue;
        };
    };
    </script>
    PHP:
    in action:
    http://mooshell.net/cSWqT/

    stay clear of naming elements that you want to reference with names like 'name' or 'id' if you can, IE can cause some weirdness in accessing these elements or their respective name or id properties.
     
    dimitar christoff, Aug 27, 2009 IP
  3. musei

    musei Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Super Cool. Now I just need it to go to the link.

    Update:

    So I added this:

    <form method="post" action="">

    <input type="text" name="id" id="clid" value="">
    <input type="submit" id="clsubmit" value="Submit">
    </form>


    Which seems to clear the form (nice), but all it really does is refresh the same page I'm on. Looking up more info to try and figure this out.
     
    Last edited: Aug 28, 2009
    musei, Aug 28, 2009 IP
  4. The PHP Guy

    The PHP Guy Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try:
    
    <form name="test" action="" method="get">
    <input type="text" name="id" id="clid" value="">
    <input type="submit" id="clsubmit" value="Submit">
    </form>
    ...
    <script type="text/javascript">
    window.onload = function() {
        document.getElementById("clsubmit").onclick = function() {
            var clid = document.getElementById("clid"), newValue = "clink://" + clid.value + "@example.com";
            clid.value = document.forms['test'].action = newValue;
        };
    };
    </script>
    
    HTML:
     
    The PHP Guy, Aug 30, 2009 IP