Manjiri Parab Manjiri Parab - 1 year ago 71
HTML Question

put variable value in textbox without onclick button in javascrip

I have made code with comments below:

which is storing value from url=> ../webdev/dummy.html?foo=quora, now my query is I want to show quora in textbox at the page load only, I don't want to use onclick function.please guide me :)


<script type="text/javascript">
function getParameterByName(name, url) {
if (!url) {
url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));

var foo = getParameterByName('foo');

document.getElementsByName('subject').Value = foo; // this is I am thinking of to store value in textbox id="subject"

<input type="text" name="subject" id="subject" readonly="true" />
<!-- textbox to display "quora" -->

it is not displaying any value in textbox

Answer Source

You have to replace the code

document.getElementsByName('subject').Value = foo;


document.getElementById('subject').value = foo;

In case you want to call it onload of the page you can use the following code,

body.onload=function(){//call your function};


window.onload=function(){//call the function}

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download