Change iframe element value

I have an iframe that I use to upload a file to my server. I want to pass the iframe the name I want for the file, but I could not do it.

I got this content in my iframe:

<html>
<body>
<form action="upload_file.php" method="post" enctype="multipart/form-data">
<input type="file" name="file" id="file"><br>
<input type="hidden" name="idProductoFormUpload" id="idProductoFormUpload"    value="test">    
<input type="submit" name="submit" value="Enviar">
</form>

iframe element code:

<iframe id="iframeUpload" name="iframeUpload" src="uploadForm.html" style="height:100px;"></iframe>

All I want to do is set the value for input idProductoFormUpload.

I tried this without success:

$('#iframeUpload').contents().find('#idProductoFormUpload').val('myValue');
+5
source share
1 answer

Your code is good. I often came across this problem. Make sure you put javascript AFTER the iframe.

+4
source

All Articles