Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass variable value from form javascript

Say I got a HTML form like below and want to pass the values in the textfields to JS variables.

<form name="testform" action="" method="?"
<input type="text" name="testfield1"/>
<input type="text" name="testfield2"/>
</form>

I've only passed values to variables in PHP before. When doing it in javascript, do I need a method? And the main question, how is it done?

like image 508
Simon Carlson Avatar asked Dec 02 '12 20:12

Simon Carlson


1 Answers

Here are a couple of examples:

Javascript:

document.getElementById('name_of_input_control_id').value;

jQuery:

$("#name_of_input_control_id").val();

Basically you are extracting the value of the input control out of the DOM using Javascript/jQuery.

like image 164
Lowkase Avatar answered Sep 30 '22 22:09

Lowkase