Tim
Tim

Reputation: 45

Using textbox as value

The last thing I cant get to work is to make this part .namefield.value = 'name'; to be based on a textarea.

I've tried altering the value part .value = 'name' to be directed to the form/id's to the textarea itself but that didn't work.

The textarea with submit button I've tried to use comes from dreamweaver;

<form id='input' method='post' action='' >
   Name: <input type='text' name='Name' />
   <input type='submit' name='submit' value='submit' />
</form>

The html/JavaScript which I am learning with is:

<html>
<head></head>
<body>
<iframe id="main" width="1000" height="1000" src="main.php"></iframe>
<button id="btnMain">Go</button>
  <script>    
     function load() {
        var btn = document.getElementById('btnMain');
        btn.onclick = function(){
        var ifrm = document.getElementById('main');
        ifrm.contentWindow.document.forms['searchForm'].namefield.value = 'name';
     };    
   }
   window.onload = load;
  </script>
</body>
</html>

In JSFiddle: http://jsfiddle.net/Tim_Holt/0a9krnao/

Upvotes: 1

Views: 92

Answers (1)

Garrett Kadillak
Garrett Kadillak

Reputation: 1060

Here's a fiddle for my solution to your problem - http://jsfiddle.net/1nqdsyhu/ Here's the snippet of HTML/jQuery code

HTML

<button id='btnMain'>Enter</button>
<input type='text' name='value instead of 'name'' value='Write your name here' />
<ul>
</ul>

</br>
</br>
The frame wich has the form hasnt been includedbecause i dont know how to, but the form        above should be the value instead of the word 'name' shown as value in de javascript, wich at this point will be placed in the iframe form.

jQuery

$(document).ready(function(){
    $('#btnMain').on('click', function() {
        $('ul').append('<li>' + $('input').val() + '</val>');
    });

});

Upvotes: 1

Related Questions