Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change value of iframe's element

Tags:

jquery

iframe

set

I got an iframe that i use to upload a file to my server. I want to pass to the iframe the name i want for the file, but i haven't been able to 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>

code of the iframe element:

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

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

I tried this with no success:

$('#iframeUpload').contents().find('#idProductoFormUpload').val('myValue');
like image 513
Albert Prats Avatar asked Feb 25 '13 12:02

Albert Prats


1 Answers

Your code is good. I often ran into this problem too. Make sure you put the javascript AFTER the iframe.

like image 171
Markus Avatar answered Sep 30 '22 00:09

Markus