Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

html forms

Options
  • 01-03-2006 12:47pm
    #1
    Registered Users Posts: 1,305 ✭✭✭


    i have a form where you enter your name and address etc. i have been trying to get the values out of these fields when you click submit using a javascript function.. but as of yet no success... any ideas as how to do this!

    thanks


Comments

  • Registered Users Posts: 7,677 ✭✭✭Trampas


    Post your code and help will be given.


  • Registered Users Posts: 1,305 ✭✭✭jobonar


    the textfield i want to get the value from:
    <input type="text" name="name" size="30" maxlength="50">

    Wat im using to get that value:
    function show()
    {
    name = document.form1.name.value;

    document.form1.submit();
    }

    then i have to get the variable value to pass into a java file:
    String name = request.getParameter("name");


  • Closed Accounts Posts: 169 ✭✭akari no ryu


    jobonar wrote:
    the textfield i want to get the value from:
    <input type="text" name="name" size="30" maxlength="50">

    Wat im using to get that value:
    function show()
    {
    name = document.form1.name.value;

    document.form1.submit();
    }

    then i have to get the variable value to pass into a java file:
    String name = request.getParameter("name");
    Personally, I find that if you're playing with a form in JS, your best bet is to do something like this
    <html>
    <head>
    <title>Javascript form manipulation</title>
    <script type="text/javascript">
    function alertForm(f){
     window.alert(f.myField.value);
     f.submit();
    }
    </script>
    </head>
    <body>
    <form name="myForm" action="someScript/URL/Whatever" method="post">
    <input type="text" name="myField"/>
    <input type="button" value="ok" onclick="alertForm(this.form)"/>
    </form>
    </body>
    

    Edit: Bug in my code, sorry, distracted by that stupid work thing.


  • Registered Users Posts: 1,275 ✭✭✭bpmurray


    I think you're mixing things up. It looks like you're trying to send the value of the field "name" to the server, where you'll process the request. This means that you should do the following:
    <html><head></head><body>
       <input type="text" id="name" size="30" maxlength="50">
       <input type="submit" value="Submit">
    </body></html>
    
    This will send the value of the text field to the server, where you can process the request in your servlet:
       String myName = request.getParameter("name");
    


  • Closed Accounts Posts: 169 ✭✭akari no ryu


    bpmurray wrote:
    I think you're mixing things up. It looks like you're trying to send the value of the field "name" to the server, where you'll process the request. This means that you should do the following:
    <html><head></head><body>
       <input type="text" id="name" size="30" maxlength="50">
       <input type="submit" value="Submit">
    </body></html>
    
    This will send the value of the text field to the server, where you can process the request in your servlet:
       String myName = request.getParameter("name");
    
    What if he wants form validation?
    Regardless, you can't proccess inputs that exist outside of a form element.


  • Advertisement
  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    jobonar wrote:
    the textfield i want to get the value from:
    <input type="text" name="name" size="30" maxlength="50">

    Wat im using to get that value:
    function show()
    {
    name = document.form1.name.value;

    document.form1.submit();
    }

    then i have to get the variable value to pass into a java file:
    String name = request.getParameter("name");
    You probably shouldn't call your textfield "name", I can't remember if it's a restricted keyword or not, but I think it could be.


  • Closed Accounts Posts: 169 ✭✭akari no ryu


    stevenmu wrote:
    You probably shouldn't call your textfield "name", I can't remember if it's a restricted keyword or not, but I think it could be.
    Good point. Much like you should never call it action, method, or any form node property.
    Case in hand, though, it is a restricted keyword because when you try to access <formObject>.name.value, it will try to access the form node's name property
    as in
    <form name="blah">
    which should return null when you try and get the value


Advertisement