16.3 C
Москва
16.07.2026

© FlashNews!


JavaScript

let page = document.querySelector(‘.page’); let themeButton = document.querySelector(‘.theme-button’); themeButton.onclick = function() < page.classList.toggle('light-theme'); page.classList.toggle('dark-theme'); >; let message = document.querySelector(‘.subscription-message’); let form = document.querySelector(‘.subscription’); // Объявите переменную здесь form.onsubmit = function(evt) < evt.preventDefault(); // Измените значение textContent на следующей строке message.textContent = 'Форма отправлена!'; >;

Показать ответ

Спасибо! Мы скоро всё исправим)

get the input box ‘name’ using javascript

I am making form in PHP and submitting using javascript. I want to get the name of input box, As normal coding gives the value of the input box, but i need to get name of input box. Without onclick functionality on it. Can it possible that retrieving the name of input box in other javascript function on click a button. for example

Now onclick a other button I am calling test() , In test() how can I get the name of the input box.
53k 38 38 gold badges 146 146 silver badges 201 201 bronze badges
asked Oct 11, 2012 at 5:59
Parth Sarthi Gour Parth Sarthi Gour
95 1 1 gold badge 2 2 silver badges 4 4 bronze badges

5 Answers 5

var txtbox = document.getElementById("d"); var txtboxname = txtbox.name; 

answered Oct 11, 2012 at 6:03
Priyank Patel Priyank Patel
6,908 11 11 gold badges 58 58 silver badges 88 88 bronze badges

u can do that by using attr function.

in yout test function add this.

$('#d').attr('name'); // this will return text_name in your case (if you are using jquery) 
var inputname=document.getElementById("d").name //javascript 

answered Oct 11, 2012 at 6:04
36.4k 9 9 gold badges 49 49 silver badges 62 62 bronze badges

put this on your javascript function

var name=document.getElementById("d").name; 

answered Oct 11, 2012 at 6:04
2,775 2 2 gold badges 15 15 silver badges 20 20 bronze badges

function test() return document.getElementById(«d»).name; >

answered Oct 11, 2012 at 6:14
81 5 5 bronze badges

Not really sure what you are trying to do, but if your script is called from a listener on a button in the form, you can do:

Then the doSubmit function is something like:

function doSubmit(el) < var form = el.form; var control, controls = form.elements; for (var i=0, iLen=controls.length; i> 

I would strongly recommend that your form has a standard submit button and works without any scripting, then you can add your scripted submission to the form’s submit handler. It can cancel the standard submit and do its own thing.

That way if script is disabled, not available or fails for some reason, the user can still submit the form.

Как получить значение из input javascript

Чтобы получить значение из элемента input , достаточно обратиться к свойству value . Например, если на странице имеется такой элемент ввода:

 id="input-id"> 

то из него можно получить значение следующим образом

const input = document.getElementById('input-id'); // Извлекаем элемент input const value = input.value; // получаем занчение из input 
Читать:
Какое отличие java от javascript

Похожие записи

Как пользоваться эпл вотч без сознания пары

admin

Колокол 21 телеграмм канал кто автор

admin

Как сделать орнамент в coreldraw

admin