2013-05-16 1 views
0

이 온라인 솔루션을 찾을 수 있다고 생각했지만 해결책을 찾지 못하는 것 같습니다.Javascript 호출에서 텍스트를 페이지의 양식에 텍스트 필드로 전달?

id = "filledonload"인 텍스트 필드가있는 양식이 있고 페이지가로드 될 때 JavaScript 함수에서 텍스트 값을 가져와야합니까? 어떻게 이뤄지나요? 나는

아래는 내 슈퍼 간단한 양식입니다 .. 더 나은 단어가 자동이 도움을

감사합니다 "를 채우는"것 같아요.

<form id="form1" name="formname" method="post" action=""> 
<label>This Field Would Grab Text From JavaScript Function When The Page Loads 
    <input type="text" name="filledonload" id="filledonload" /> 
</label> 

이 작업을 수행하는 데 필요한받을 수 있나요? 내가하지 희망.

답변

0

기본적으로 기능을 body 태그에 추가하고 거기에서 수행해야합니다.

<html> 
    <head> 
    <script> 
    function doLoad(){ 
     //get the the input element and set the value 
     var inp = document.getElementById('filledonload'); 
     inp.value = yourJsFunc(); 
    } 

    function yourJsFunc(){ 
     //return whaterever you want here 
     return 'value on load'; 
    } 
    </script> 
    </head> 
    <body onload="doLoad()"> 
    <form id="form1" name="formname" method="post" action=""> 
    <label>This Field Would Grab Text From JavaScript Function When The Page Loads 
     <input type="text" name="filledonload" id="filledonload" /> 
    </label> 
    </body> 
</html> 
+0

나는이 기능을 사용할 수 없습니다. 그것은 나의 무언가가 내게 잘못되었음을 나에게 알리게한다. 나는 밤새도록 기쁨없이 스크립트를 시험해 보았습니다. –

+0

감사합니다. fmodos, jsFiddle에서 아무런 기쁨없이 사용해 보았습니다. 내가 뭘 잘못했는지 알아? 확인 해봐. http://jsfiddle.net/alwaysfinding/gYgcQ/ –

+0

죄송합니다. yourjsfunc 및 스크립트 닫기 태그에 잘못된 이름을 입력했습니다 ... 저는 전화이며 지금은 테스트 할 수 없지만 작동 할 것입니다. – fmodos

관련 문제