Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
here is my html codes

HTML
<input type="text" name="textBox" id="textBox"/>

<a input type="button" class="btn" id="btnSeven" >Generate Birthday</a>



this is my javascript function

JavaScript
<script>
        function myFunction()
        {
        alert("Page is loaded");
        }


C#
document.getElementById('btnSeven').onclick =  myFunction(){
 document.getElementById('textBox').value = document.getElementById('btnSeven').value;


});

</script>

now i want to pass function value to text box after i clicked the button.
Posted
Comments
SRS(The Coder) 25-Jun-14 1:32am    
What i understood from your question you want to set the text of the textbox to the value returned by the function you created. So i have added the solution as below. PLease let me know if my understanding is wrong any where ?

You can achieve this one very easily using jQuery.

For this you have to include the jQuery file to your page where you want to make use of it.
For me the jquery file is at root of the project itself.
HTML
<script src="jquery-2.0.3.js"></script>


Here is an example as per your code description :-

In page let say we have two elements like
1. Button
HTML
<input type="button" class="btn" id="btnSeven" value="Generate Birthday" />


2. TextBox
HTML
<input type="text" name="textBox" id="textBox" /> 


Then to set the textbox value on click of button by calling the method which returns the value :-

JavaScript
$(function () {
            $("#btnSeven").on("click", function () {
                $("#textBox").val(myfunction());
            });
        });

        function myfunction() {
            return "myvalue";
        }


Hope this will help. Please let me know if you need any more help on it.
 
Share this answer
 
Comments
Hemas Ilearn 25-Jun-14 6:32am    
Thank you. It helps lot.........

actually i'm doing a birthday generate thing.

and i want to know
how to compare a variable with an array in jquery?
Just do like this

$(document).ready(function () {<br />
    $("#btnSeven").click(function () {<br />
        $("#textBox").val(myFunction());<br />
    });<br />
});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900