#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Posts
    2
    Rep Power
    0

    Passing JavaScript variables in HTML Form


    Hello all, this is my first posting here....

    In a nutshell, I have some HTML text Fields for First and Last name entry. With those fields I have to create a single Name Variable (which I have), but send that single variable thru my HTML Form. I have tired a number of different approaches, but have been unsuccessful so far.

    I have tried setup a function that first validates the entered data, creates the single name variable and returns that variable value, but I have not been able to pick up that value with my HTML Form.

    If anyone might be able to give me some direction on how to pick up that JavaScript variable with my HTML, you'd make me a happy camper )

    Thanks All
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2001
    Posts
    765
    Rep Power
    14
    Guess you must have a reason.

    <html>
    <head>
    </head>
    <body>
    <div align="center">
    <form name="nameTemp">
    First Name: <input name="firstName" type="text"><br>
    Last Name: <input name="lastName" type="text">
    </form>
    <form name="mainForm" onsubmit="return singleName(this)">
    age: <input name="age" type="text" value="35"><br>
    gender: <input name="gender" type="text" value="male"><br>
    sex: <input name="sex" type="text" value="yes"><br>
    <input name="firstLast" type="hidden">
    <input type="submit">
    </form>
    </div>

    <script type="text/javascript">

    function singleName(form)
    {
    if (document.nameTemp.firstName.value == '')
    {
    alert('Please enter your first name.');
    document.nameTemp.firstName.focus();
    return false;
    }
    if (document.nameTemp.lastName.value == '')
    {
    alert('Please enter your last name.');
    document.nameTemp.lastName.focus();
    return false;
    } else {
    form.firstLast.value = document.nameTemp.firstName.value + document.nameTemp.lastName.value;
    }
    return true;
    }

    </script>
    </body>
    </html>
    Last edited by mrrichardfeder; December 12th, 2001 at 03:31 PM.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Posts
    2
    Rep Power
    0
    thanks for the example, worked out fine. the reason was my clients wanted two input fields, but the backend data required one field with full name. Thanks, therick

IMN logo majestic logo threadwatch logo seochat tools logo