Home > Net >  Javascript multiple input name value
Javascript multiple input name value

Time:10-25

I need to get some javascript information from the input and I should have something like this:

&hostname1=someValue1&RecordType1=someValue1&Address1=someValue1&hostname2=someValue2&RecordType2=someValue2&Address2=someValue2&hostnameN=someValue&RecordTypeN=someValue&AddressN=someValue

$("#dnsRecordsForm").submit(function(e){
    e.preventDefault();
    let HostName = $("[name='HostName']");
    let RecordType = $("[name='RecordType']");
    let Address = $("[name='Address']");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="dnsRecordsForm" onsubmit="alert(new URLSearchParams(new FormData(this)));">
  <div>
    ...
    <input type="hidden" name="HostName[]" value="someValue1">
    <input type="hidden" name="RecordType[]" value="someValue1">
    <input type="hidden" name="Address[]" value="someValue1">
  </div>
  <div>
    ...
    <input type="hidden" name="HostName[]" value="someValue2">
    <input type="hidden" name="RecordType[]" value="someValue2">
    <input type="hidden" name="Address[]" value="someValue3">
  </div>
  <div>
    ...
    <input type="hidden" name="HostName[]" value="someValueN">
    <input type="hidden" name="RecordType[]" value="someValueN">
    <input type="hidden" name="Address[]" value="someValueN">
  </div>
  ...
  <button type="submit">Validate</button>
</form>

I'm not sure where to start, do you have an idea?

Sincerely

CodePudding user response:

Use form method as GET to get the expected query string in the URL bar on form submit.

CodePudding user response:

I don't need to post it, i need to have the value in javascript like that:

let value="&hostname1=someValue1&RecordType1=someValue1&Address1=someValue1&hostname2=someValue2&RecordType2=someValue2&Address2=someValue2&hostnameN=someValue&RecordTypeN=someValue&AddressN=someValue"
  • Related