Need help with passing data to new url.

Discussion in 'Javascript' started by bjorgenson@charter.net, Jun 15, 2005.

  1. Guest

    Here is my dilema: I want a form that includes an input box and submit
    button. A user will type in some data in the input box. When they click
    submit, I need set variables appended to this input text and then
    passed on to the same page "_parent" as a new url.

    For example:

    The user types in "mycomputer". When submited, I need to add the
    following text to the beginning and end of "mycomputer"


    http://mycomputer:8000/mysite

    Where "http://" would = variable1 and ":8000/mysite" would = variable2

    Thanks,
    Brian
     
    , Jun 15, 2005
    #1
    1. Advertising

  2. Guest

    Was able to figure it out:

    <html>
    <body>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function submitForm( Form1 )
    {
    if ( Form1.newurl.value == "" )
    {
    alert( "Please enter a valid IP or computer name" );
    return;
    }

    Form1.action = "http://"
    + Form1.newurl.value
    + ":5800";
    Form1.submit();

    }

    // -->
    </SCRIPT>

    <FORM NAME="myForm" METHOD="post">
    <INPUT TYPE="text" NAME="newurl">
    <INPUT TYPE="button" VALUE="Connect" ONCLICK="submitForm(this.form);">
    </FORM>
    </body>
    </html>
     
    , Jun 15, 2005
    #2
    1. Advertising

  3. Zif Guest

    wrote:
    > Was able to figure it out:


    No, you didn't...

    >
    > <html>
    > <body>
    > <SCRIPT LANGUAGE="JavaScript">


    The language attribute is depreciated, type is required:

    <script type="text/javascript">

    > <!--


    Attempting to hide scripts is pointless and possibly harmful, don't bother.

    > function submitForm( Form1 )
    > {
    > if ( Form1.newurl.value == "" )
    > {
    > alert( "Please enter a valid IP or computer name" );
    > return;
    > }
    >
    > Form1.action = "http://"
    > + Form1.newurl.value
    > + ":5800";
    > Form1.submit();
    >
    > }
    >
    > // -->
    > </SCRIPT>
    >
    > <FORM NAME="myForm" METHOD="post">
    > <INPUT TYPE="text" NAME="newurl">
    > <INPUT TYPE="button" VALUE="Connect" ONCLICK="submitForm(this.form);">


    If the user types some text into the input and presses return, the form
    is submitted without your onclick running. Put your onclick function
    into the form onsubmit event and no matter how the form is submitted, it
    will run (provided your user has javascript enabled).

    You should provide an alternative if javascript is not working, say a
    redirect from your server based on the value returned in the form or at
    very least a default action that explains why the form doesn't work.

    > </FORM>
    > </body>
    > </html>
    >


    Try:

    <script type="text/javascript">

    function initForm(f) {
    document.forms[f].onsubmit = function() {return submitForm(this); };
    }

    function submitForm( Form1 ) {
    if ( Form1.newurl.value == "" ) {
    alert( "Please enter a valid IP or computer name" );
    return false;
    }
    Form1.action = "http://"+Form1.newurl.value+":5800";
    }

    window.onload = function() { initForm('myform');};

    </script>
    <form name="myform" action="You_Dont_Have_JS_Enabled.html"
    method="post">
    <input type="text" name="newurl">
    <input type="submit" value="connect">
    </form>



    --
    Zif
     
    Zif, Jun 15, 2005
    #3
  4. Guest

    I'm no JS expert but your code solves the "onclick" issue. Thanks!

    Another thing, can anybody tell me why there is a "-" after my value? I
    am now getting "http://ip-address-:5800"

    Brian
     
    , Jun 16, 2005
    #4
  5. Guest

    I'm no JS expert but your code solves the "onclick" issue. Thanks!

    Another thing, can anybody tell me why there is a "-" after my value? I
    am now getting "http://ip-address-:5800"

    Brian
     
    , Jun 16, 2005
    #5
  6. Grant Wagner Guest

    <> wrote in message
    news:...
    > I'm no JS expert but your code solves the "onclick" issue. Thanks!
    >
    > Another thing, can anybody tell me why there is a "-" after my value?
    > I
    > am now getting "http://ip-address-:5800"


    Because you're appending one? Because you're typing one into the input
    box? Without seeing your now "working" code, there's no way to know why
    you are constructing the string you are constructing.

    --
    Grant Wagner <>
    comp.lang.javascript FAQ - http://jibbering.com/faq
     
    Grant Wagner, Jun 24, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon paugh
    Replies:
    1
    Views:
    753
  2. Moderator
    Replies:
    0
    Views:
    297
    Moderator
    Jul 28, 2006
  3. Just D.
    Replies:
    0
    Views:
    443
    Just D.
    Aug 11, 2004
  4. Replies:
    0
    Views:
    89
  5. Replies:
    2
    Views:
    467
    Thomas 'PointedEars' Lahn
    Mar 11, 2008
Loading...

Share This Page