最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

how to pass input(type = text ) from a html form to javascript function - Stack Overflow

programmeradmin1浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论