How to write data from Form in HTML to XML with Javascript

后端 未结 3 787
[愿得一人]
[愿得一人] 2020-12-10 07:50

This is an assignment from my class. What I need to do is create a registration page. When the user presses the submit button, I have take all the information on the form an

3条回答
  •  没有蜡笔的小新
    2020-12-10 08:02

    Isn't it cheating to ask us? Your implementation will probably only work in IE, I'd recommend using jQuery as it is impressively powerful at parsing XML.

    I'm not sure why he wants you to write out XML as it's not very intuitive coming from JavaScript. You can do something like this via jQuery

    //I capture form submitevent
    
    $('form').submit(function( ev ){
      ev.preventDefault(); //I keep form from submitting
      $( xmlDocument ).find('Person').attr({
        username: $("input[name=usrname]),
        password: $("input[name=pswd]),
        //and so on
      });
    
    });
    

    It's up to you on how you 'report' this xml file

提交回复
热议问题