admin管理员组

文章数量:1427140

i want to pass the udid taken from textfield to function getusername.

<tr>
     <td> Enter Udid : </td>
     <td> <input name="udid" id="udid" type="text" value="{{udid}}" size="50"></td>
</tr>

<td> 
     <input type="button" value="Get User Name(udid)" onclick="getUserName(udid);"> 
</td>

i want to pass the udid taken from textfield to function getusername.

<tr>
     <td> Enter Udid : </td>
     <td> <input name="udid" id="udid" type="text" value="{{udid}}" size="50"></td>
</tr>

<td> 
     <input type="button" value="Get User Name(udid)" onclick="getUserName(udid);"> 
</td>
Share Improve this question asked Sep 13, 2012 at 7:27 yasiryasir 1372 silver badges14 bronze badges 1
  • I am not really a pro in javascript, but i think you should pass id of the element, since u are initializing id=udid. – Shafi Commented Sep 13, 2012 at 7:31
Add a ment  | 

2 Answers 2

Reset to default 3

This should work:

onclick="getUserName(document.getElementById('udid').value);"

Try this code:

In your html:

<input type="button" value="Get User Name(udid)" onclick="getUserName(document.getElementById('udid'));">

Function javascript:

function getUserName(id){
    alert(id.value);
}

Look at this demo: JSFIDDLE

本文标签: how to pass input(typetext ) from a html form to javascript functionStack Overflow