Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing javascript variable to html textbox

i need help on html form.

I got a javascript variable, and I am trying to pass the variable to a html form texbox. I want to display the variable on the textbox dynamically. but i do not know how to pass the variable to the html form and call the variable?

var test;

<INPUT TYPE="TEXT" NAME="lg" VALUE="" SIZE="25" MAXLENGTH="50" disabled="disabled"><BR><BR>

How do i pass test to html form and change its value?

Thanks

like image 580
Dayzza Avatar asked Nov 23 '10 02:11

Dayzza


3 Answers

instead of

document.getElementById("txtBillingGroupName").value = groupName;

You can use

$("#txtBillingGroupName").val(groupName);

instead of groupName you can pass string value like "Group1"

like image 170
Nikhil Patel Avatar answered Sep 20 '22 23:09

Nikhil Patel


Pass the variable to the form element like this

your form element

<input type="text" id="mytext">

javascript

var test = "Hello";
document.getElementById("mytext").value = test;//Now you get the js variable inside your form element
like image 24
John Hartsock Avatar answered Nov 08 '22 11:11

John Hartsock


<form name="input" action="some.php" method="post">
 <input type="text" name="user" id="mytext">
 <input type="submit" value="Submit">
</form>

<script>
  var w = someValue;
document.getElementById("mytext").value = w;

</script>

//php on some.php page

echo $_POST['user'];
like image 4
David Avatar answered Nov 08 '22 12:11

David