Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

105
Views
Cambie el nombre de entrada de acuerdo con un botón específico en JS

Estoy tratando de crear o importar algunos datos.

Si existen datos, estoy mostrando el botón de importar y si no existieran, estoy mostrando el botón de crear. Estoy trabajando con autocompletar (jquery-ui)

Así que este es mi html:

 <input name="Test" id="aff" type="text" oninput="onInput(this.value)" class="form-control"> <button id="create" type="submit" >Create</button>--> <button id="import" type="submit" style="display: none">Import</button> </form>

Solo quiero saber si es posible cambiar el atributo de nombre de un texto de entrada. Entonces, si hago clic en importar, el nombre de la entrada será:

 <input name="Test"

Y si hago clic en crear, el nombre de la entrada será:

 <input name="Test2"

Nota: quiero usar solo una entrada y no 2 entradas con estos dos nombres diferentes

Alguien me puede ayudar y decir si es posible

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Sí, puede cambiar el valor del atributo de name usando el método attr() :

 $("#btnCreate").click(function(){ $("#aff_qp").attr("name","affId"); console.log($("#aff_qp").attr("name")); }); $("#btnExport").click(function(){ $("#aff_qp").attr("name","aff[code]"); console.log($("#aff_qp").attr("name")); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input id="aff_qp" type="text" name="aff[code]" /> <button id="btnCreate">Create</button> <button id="btnExport">Export</button>

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!