Welcome visitor
* Login
* Register
It is currently May 25th, 2019, 9:17 pm
All times are UTC [ DST ]
* Search
View unanswered posts - View active topics

FORUMS » Client Side » JavaScript



Post new topic Reply to topic  [ 2 posts ] 
Author Message
  Create a $_POST array with JavaScript (and a table with it)
PostPosted: November 27th, 2009, 10:16 am 

Posts: 10
Hi, I think there should be a way with javascript and it functions to go through the fields of a form. What I want to do is to create something like the PHP $_POST array but with javascript only. I would like to create a table with each field, its type and value. If you can give me links I will really appreciate it.


Top
 Profile  
 
  Re: Create a $_POST array with JavaScript (and a table with it)
PostPosted: November 27th, 2009, 3:32 pm 
User avatar

Posts: 112
This doesn't create the array, it gets the info though :D , and store it in different arrays. It still has its differences between PHP.
<script type="text/javascript">
function loopit(){
  var names=new Array();
  var values=new Array();
  var checkitem=new Array();
  var itemtype=new Array();
  area=document.getElementById('inner');
  for(i=0; i<document.form.length; i++){
    names[i]=document.form.elements[i].name;
    values[i]=document.form.elements[i].value;
    itemtype[i]=document.form.elements[i].type;
    if(document.form.elements[i].checked==true){
        checkitem[i]='checked';
    }
    else{
        checkitem[i]='';
    }
    if(i==0){
      area.innerHTML+='<table><tr><td>'+names[i]+'</td><td>'+values[i]+'</td>
      <td>'+itemtype[i]+'</td><td>'+checkitem[i]+'</td><tr>';
    }
    else if(i==document.form.length-1){
      area.innerHTML+='<tr><td>'+names[i]+'</td><td>'+values[i]+'</td>
      <td>'+itemtype[i]+'</td><td>'+checkitem[i]+'</td><tr></table>';
    }
    else{
      area.innerHTML+='<tr><td>'+names[i]+'</td><td>'+values[i]+'</td>
      <td>'+itemtype[i]+'</td><td>'+checkitem[i]+'</td><tr>';
    }
  }
}
</script>
<div id="inner">table will go here</div>

Also, this table will include even the disabled and any type of input. Of course you can go through more validation, this was just a quick glance. Cheers.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

FORUMS » Client Side » JavaScript


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron