We help IT Professionals succeed at work.

how can i collect all data from one form with javascript

galic1987
galic1987 asked
on
1,066 Views
Last Modified: 2008-01-09
how can i collect all data from one POST form with javascript by only knowing form name?
 just want to send post request thru ajax and get response.

but my problem is how to collect.
Comment
Watch Question

CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
great thank you, one question more:
how can I extend that with radio button?
CERTIFIED EXPERT

Commented:
thanks, glad to help you

now with radio buttons:
==================================
<form name=myForm method="post" action="http://www.sembel.net/tools/q.php">
      <input type=text name=city value=Athens>      
      <input type=text name=country value=Greece>
      <input type=radio name=sex value=f>
      <input type=radio name=sex value=m>
      <input type="submit">
</form>

<script>
document.myForm.onsubmit = new Function("return smb()");
function smb()
{
      var els = document.myForm.elements;
      var str = "";
      for(var i=0; i<els.length; i++)
      {
            if(els[i].type != "submit")
            {
                  if(els[i].type == "radio")
                  {
                        if(els[i].checked)
                        {
                              if(i > 0)str += "&";
                              str += els[i].name + "=" + els[i].value;
                        }
                  }
                  else
                  {
                        if(i > 0)str += "&";
                        str += els[i].name + "=" + els[i].value;
                  }
            }
      }
      alert(str);
      return false;
}
</script>

Author

Commented:
thank you very much!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.