Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 15671

Split URL In Js

$
0
0

I have a html code that contains a table with a form there are supposed to go names and surnames on the other hand I have the js that gets them and puts them in the url at this time I need to go to another page and separate them to use them but only separates me the first and last name

HTML:

<form id="Estudiantes" action="Pagina2.html"><table border="0" class="tabla"><tr><td colspan="3" class="title">Students</td></tr><tr><td>name</td><td>Lastname</td><td rowspan="5"><img src="img.png" width="200" height="180"></td></tr>   <tr><td><input name="name" type="text" placeholder="" required></td><td><input name="lastname" type="text" placeholder="" required></td></tr><tr><td><input name="name" type="text" placeholder="" required></td><td><input name="lastname" type="text" placeholder="" required></td></tr><tr><td><input name="name" type="text" placeholder="" required></td><td><input name="lastname" type="text" placeholder="" required></td></tr><tr><td><input name="name" type="text" placeholder="" required></td><td><input name="name" type="text" placeholder="" required></td></tr><tr><td colspan="3" style="text-align: center;"><button id="boton" type="submit">Send</button></td></tr></table></form>

First Js:

document.getElementById("Students").addEventListener("submit", function (event){    event.preventDefault();    var formData = new FormData(this);    var data =  {};    for(var [key, value] of  formData.entries()){        if(!data[key]){            data[key] =  [];        }        data[key].push(value);    }    var queryString   =Object.keys(data).map(function(key){        return encodeURIComponent(key) +"," +   encodeURIComponent(data[key]);    }).join('&');    window.replace(urlnew);     return true;});

Second js:

function getdata(){    var params =   new URLSearchParams(window.location.search);    var name = params.get('name').split(",");    var lastname  = params.get('lastname').split(",");    for(var  i   =  0; i < nombres.length; i++){        var nameCell  = document.getElementById("name"  + (i +  1));        var lastnameCell  = document.getElementById("lastname"  + (i +  1));        nameCell.textContent   = name[i];        lastnameCell.textContent = lastname[i];    }}window.onload =  function(){    getdata();}

To be able to separate first and last names in order to be able to use them with an id on a td


Viewing all articles
Browse latest Browse all 15671

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>