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="submit" value="Upload">
<input type="hidden" name="email" id="email" value="">
</form>
I have to set the value of the hidden field to an email like "[email protected]". I can obtain this value from adding a querystring parameter by external iframe like:
<iframe name="[email protected]" src="[email protected]">
Ok. But how can I set value="" to value="[email protected]"? I know have to use javascript, but I dunno how to deal with the var.
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="submit" value="Upload">
<input type="hidden" name="email" id="email" value="">
</form>
I have to set the value of the hidden field to an email like "[email protected]". I can obtain this value from adding a querystring parameter by external iframe like:
<iframe name="[email protected]" src="[email protected]">
Ok. But how can I set value="" to value="[email protected]"? I know have to use javascript, but I dunno how to deal with the var.
Share Improve this question edited Jul 9, 2012 at 10:50 Gareth 138k36 gold badges151 silver badges158 bronze badges asked Jul 9, 2012 at 10:44 user840718user840718 1,6117 gold badges36 silver badges61 bronze badges 2- 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 Commented Jul 9, 2012 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 Commented Jul 9, 2012 at 10:51
3 Answers
Reset to default 3document.getElementById('Id').value='new value';
answer to ment: try this:
<input type="" name="email" id="email">
<iframe id="frm" name="[email protected]" src="[email protected]">
</iframe>
<script>
document.getElementById('email').value = document.getElementById('frm').name;
</script>
then you can change adopt it. change type to hidden and etc.
If your script is executed from the document inside the iframe, you can do this :
var getUrlParameter = function(name, defaultValue) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( document.location.href );
if( results == null ) return defaultValue;
else return decodeURIComponent(results[1]);
};
document.getElementById('email').value=getUrlParameter('email');
As you've labeled this question as jQuery You can use $('#Id').val('new value');
But don't forget to add jQuery Library.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744767688a4592560.html
评论列表(0条)