?
Solved

Fill form-field in 1 form with the value of a form-field in another form.

Posted on 2012-08-15
5
Medium Priority
?
621 Views
Last Modified: 2012-08-16
Hi,

I'm trying to fill a form-field in 1 form with the value of a form-field in another form.

This is not working for form-fields that are not in the same form, i think.

$("#mainmenu").change( function() {
$("#mainvalue").val($(this).val());
});

mainmenu = i n form 1 / mainvalue = in form 2

How can i get it working?
0
Comment
Question by:peps03
  • 2
  • 2
5 Comments
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 38298006
Works for me
<!doctype html>
<html>
<head>
<title>EE Test</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
	$('#mainmenu').change(function() {
		$('#mainvalue').val($(this).val());
	});
});
</script>
<body>
<form>
	Form 1<input type="text" id="mainmenu" />
</form>
<form>
	Form 2<input type="text" id="mainvalue" />
</form>
</body>
</html>

Open in new window

0
 

Author Comment

by:peps03
ID: 38298542
Oke, thanks
but it doesn't work here..

Does it matter that #mainmenu is a select input
and #mainvalue is a hidden input? i guess not..

i can't figure out why it wouldn't work.

Does it matter that there is also an ajax call done in the same change function?
Creating another change function also didn't help

BTW, moving the hidden field to the other form also didn't help the problem.. so that's not it.
0
 
LVL 17

Accepted Solution

by:
sonawanekiran earned 2000 total points
ID: 38299155
Look at this test page: http://jsfiddle.net/gZnKv/3/
0
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 38299521
Ok two things

1. Did you try the posted code - did that work or not?
2. Can you post more of your code or give a link to a page because there is obviously something on your side that has not been described here which is making your solution fail.

The code I posted works - so if you are using the same logic we need to see more of the code to see why it is not working for you.

I assume javascript is enabled on the browser ??
0
 

Author Closing Comment

by:peps03
ID: 38299851
Thanks for the help!

This now works. Maybe i had a typo.

Thanks a million!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question