Take the 2-minute tour ×

I have a simple form like this one:

<form ENCTYPE="multipart/form-data" action="upload.php" method="POST">
<p>UPLOAD FILE: <input type="file" name="file1"> <br /></p>
<input type="hidden" name="email" id="email" value="">

I have to set the value of the hidden field to an email like "email@email.com". I can obtain this value from adding a querystring parameter by external iframe like:

<iframe name="email@email.com" src="index.html?email=email@email.com">

Ok. But how can I set value="" to value="email@email.com"? I know have to use javascript, but I dunno how to deal with the var.

share|improve this question
You could also fill it in on the server side if you want - you could get your index.html to use some server-side processing, take the email parameter and insert it into the field when you generate the form. But it's easy enough to do this with JavaScript too. –  Rup Jul 9 '12 at 10:46
See this question to extract the query string values. Some of the solutions may be a bit over-the-top for what you need but they're robust too. –  Rup Jul 9 '12 at 10:51

3 Answers 3

up vote 3 down vote accepted
document.getElementById('Id').value='new value';

answer to comment: try this:

<input type="" name="email" id="email">

<iframe id="frm" name="email@email.com" src="index.html?email=email@email.com">

document.getElementById('email').value = document.getElementById('frm').name;

then you can change adopt it. change type to hidden and etc.

share|improve this answer
Ok it works but this value is dynamic. I have to extract it from the querystring parameter by external iframe. This is my problem :/ –  user840718 Jul 9 '12 at 10:49
@user840718 see update. –  F0G Jul 9 '12 at 10:56

If your script is executed from the document inside the iframe, you can do this :

var getUrlParameter = function(name, defaultValue) {
    var regex = new RegExp( regexS );
    var results = regex.exec( document.location.href );
    if( results == null ) return defaultValue;
    else return decodeURIComponent(results[1]);

share|improve this answer
@Rup you're right. Edited. –  dystroy Jul 9 '12 at 10:58
Ok this worked for me. Thanks. –  user840718 Jul 9 '12 at 11:00

As you've labeled this question as jQuery You can use $('#Id').val('new value'); But don't forget to add jQuery Library.

share|improve this answer
Told other user that the var is dynamic. I dunno how can I deal with the val('new value'). –  user840718 Jul 9 '12 at 10:51

Your Answer


