943,177 Members | Top Members by Rank

Ad:
Sep 3rd, 2010
0

accessing form fields inside javascript

Expand Post »
hello guys i am facing a problem in accessing form elements and returing them.. can u please help me.. ?

Here the problem goes:
<script language="javascript" type="text/javascript">

function pop() {
newwindow2=window.open('','name','height=500,width=500');
var tmp = newwindow2.document;
tmp.write('<html><head><title>popup</title>');
tmp.write('<body><form action ="hello.html" value="somthing" method="post">');
tmp.write('<b>Date</b>')
tmp.write('<input type="text" name="date"><br>');
tmp.write('<b>Event Title</b>')
tmp.write('<input type="text" name="title"><br>');
var title = document.getElementById('title')
tmp.write('<b>Event Desc</b>');
tmp.write('<input type="text" name="event1"><br>');
tmp.write('<b>start time</b>');
tmp.write('<input type="text" name="start"><br>');
tmp.write('<b> end time </b>');
tmp.write('<input type="text" name="end"><br>');
tmp.write('<input type="submit" name="ADD" onclick="javascript:self.close()"><br>');
tmp.write('<input type="reset" name="CLEAR">');
//name = oForm.elements["title"].value;
tmp.write('</form>')
tmp.write('</body></html>');
tmp.close();

}

</script>
Here i have created a pop up (html page) inside one html page which uses javascript inside it. On clicking submit in the popup i want the values of form elements (& also return those values to other html page ) so can u ppl help in this regard
Thank you
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
yopirates is offline Offline
34 posts
since Feb 2010
Sep 4th, 2010
0
Re: accessing form fields inside javascript
copy and paste the following and give it a try:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head>
  7. <title></title>
  8. <script type="text/javascript">
  9. var data=null;
  10. function gatherData(f)
  11. {
  12. var str={};
  13. var i=-1, limit=f.elements.length;
  14. while( ++i < limit)
  15. {
  16. str[ f.elements[i].name ] = f.elements[i].value;
  17. }
  18. data=str;
  19. alert( data['title'] );
  20. }
  21.  
  22.  
  23. function pop() {
  24. newwindow2=window.open('','name','height=500,width=500');
  25. var tmp = newwindow2.document;
  26. tmp.write('<html><head><title>popup</title>');
  27. tmp.write('<body><form action ="hello.html" method="post" onsubmit="return self.opener.gatherData(this);">');
  28. tmp.write('<b>Date</b>')
  29. tmp.write('<input type="text" name="date"><br>');
  30. tmp.write('<b>Event Title</b>')
  31. tmp.write('<input type="text" name="title"><br>');
  32. var title = document.getElementById('title')
  33. tmp.write('<b>Event Desc</b>');
  34. tmp.write('<input type="text" name="event1"><br>');
  35. tmp.write('<b>start time</b>');
  36. tmp.write('<input type="text" name="start"><br>');
  37. tmp.write('<b> end time </b>');
  38. tmp.write('<input type="text" name="end"><br>');
  39. tmp.write('<input type="submit" name="ADD"><br>');
  40. tmp.write('<input type="reset" name="CLEAR">');
  41. //name = oForm.elements["title"].value;
  42. tmp.write('</form>')
  43. tmp.write('</body></html>');
  44. tmp.close();
  45.  
  46. }
  47.  
  48. </script>
  49. </head>
  50. <body>
  51. <span onclick="pop()">Popup</span>
  52. </body>
  53. </html>
Reputation Points: 116
Solved Threads: 243
Veteran Poster
hielo is offline Offline
1,123 posts
since Dec 2007
Sep 6th, 2010
0
Re: accessing form fields inside javascript
hi hielo
thanks for the reply in the thread "accessing form fields inside javascript"
actually iam using a fullcalander for my work.
The solution which u gave helped me to display the current event which i typle in an alert box ..but i want that event to be putup onto calendar..
it would be very greatfull if u help me regarding this problem
click here to see the original

http://arshaw.com/js/fullcalendar/ex...electable.html

Here they have used a promt box!! what ever they enter its being listed on the calendar page.. but in my case what i want is that i got a promt box with form fields.. when i give the title n submit that particular evnt mst be updated on to the calander ..
Thanks
Regards
Yopirates
Reputation Points: 10
Solved Threads: 0
Light Poster
yopirates is offline Offline
34 posts
since Feb 2010
Sep 6th, 2010
0
Re: accessing form fields inside javascript
This is a far as I go:

html Syntax (Toggle Plain Text)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html>
  3. <head>
  4. <base href="http://arshaw.com/js/fullcalendar/examples/" />
  5. <link rel='stylesheet' type='text/css' href='../fullcalendar.css' />
  6. <script type='text/javascript' src='../jquery/jquery.js'></script>
  7. <script type='text/javascript' src='../jquery/jquery-ui-custom.js'></script>
  8. <script type='text/javascript' src='../fullcalendar.min.js'></script>
  9. <script type='text/javascript'>
  10. var data=null;
  11. var newwindow2=null;
  12. var calendar=null;
  13. $(document).ready(function() {
  14.  
  15. var date = new Date();
  16. var d = date.getDate();
  17. var m = date.getMonth();
  18. var y = date.getFullYear();
  19.  
  20. calendar = $('#calendar').fullCalendar({
  21. header: {
  22. left: 'prev,next today',
  23. center: 'title',
  24. right: 'month,agendaWeek,agendaDay'
  25. },
  26. selectable: true,
  27. selectHelper: true,
  28. select:pop,
  29. /*
  30. select: function(start, end, allDay) {
  31. var title = prompt('Event Title:');
  32. if (title) {
  33. calendar.fullCalendar('renderEvent',
  34. {
  35. title: title,
  36. start: start,
  37. end: end,
  38. allDay: allDay
  39. },
  40. true // make the event "stick"
  41. );
  42. }
  43. calendar.fullCalendar('unselect');
  44. },
  45. */
  46. editable: true,
  47. events: [
  48. {
  49. title: 'All Day Event',
  50. start: new Date(y, m, 1)
  51. },
  52. {
  53. title: 'Long Event',
  54. start: new Date(y, m, d-5),
  55. end: new Date(y, m, d-2)
  56. },
  57. {
  58. id: 999,
  59. title: 'Repeating Event',
  60. start: new Date(y, m, d-3, 16, 0),
  61. allDay: false
  62. },
  63. {
  64. id: 999,
  65. title: 'Repeating Event',
  66. start: new Date(y, m, d+4, 16, 0),
  67. allDay: false
  68. },
  69. {
  70. title: 'Meeting',
  71. start: new Date(y, m, d, 10, 30),
  72. allDay: false
  73. },
  74. {
  75. title: 'Lunch',
  76. start: new Date(y, m, d, 12, 0),
  77. end: new Date(y, m, d, 14, 0),
  78. allDay: false
  79. },
  80. {
  81. title: 'Birthday Party',
  82. start: new Date(y, m, d+1, 19, 0),
  83. end: new Date(y, m, d+1, 22, 30),
  84. allDay: false
  85. },
  86. {
  87. title: 'Click for Google',
  88. start: new Date(y, m, 28),
  89. end: new Date(y, m, 29),
  90. url: 'http://google.com/'
  91. }
  92. ]
  93. });
  94.  
  95. });
  96.  
  97. function trim(s)
  98. {
  99. if(typeof(s)=="undefined")
  100. return "";
  101. return String(s).replace(/^\s+|\s+$/g,'');
  102. }
  103. function gatherData(f)
  104. {
  105. var str={};
  106. var i=-1, limit=f.elements.length;
  107. while( ++i < limit)
  108. {
  109. str[ f.elements[i].name ] = trim(f.elements[i].value);
  110. }
  111. data=str;
  112. // document.getElementById("title").innerHTML=data["title"];
  113. // document.getElementById("date").innerHTML=data["date"];
  114. var errs=[];
  115. if(!data.title)
  116. errs[errs.length]="Title is required";
  117.  
  118. if(!data.start)
  119. errs[errs.length]="Start Time is required";
  120.  
  121. if(!data.end)
  122. errs[errs.length]="End Time is required";
  123.  
  124. if (!errs.length)
  125. {
  126. calendar.fullCalendar('renderEvent',
  127. {
  128. 'title': data.title,
  129. 'start': new Date( Date.parse( data.date + " " + data.start) ),
  130. 'end': new Date( Date.parse( data.date + " " + data.end) ),
  131. 'allDay': false
  132. },
  133. true // make the event "stick"
  134. );
  135. calendar.fullCalendar('unselect');
  136. newwindow2.close();
  137. }
  138. else
  139. {
  140. alert( "The information you submitted contains errors, specifically: \n\t" + errs.join("\n\t"));
  141. setTimeout(function(){newwindow2.focus();},50);
  142. }
  143. return false;
  144. }
  145.  
  146.  
  147. function pop(s) {
  148. newwindow2=window.open('','name','height=500,width=500');
  149. newwindow2.onload=function(){
  150. var strD=(s.getMonth()+1) + '/' + s.getDate() + '/'+ s.getFullYear();
  151. newwindow2.document.getElementById("date").value=strD;
  152. }
  153.  
  154. var tmp = newwindow2.document;
  155. tmp.write('<html> <head> <title> popup</title> ');
  156. tmp.write('<body> <form action ="hello.html" method="post" onsubmit="return self.opener.gatherData(this);"> ');
  157. tmp.write('<b> Date</b> ')
  158. tmp.write('<input type="text" id="date" name="date" readonly="readonly"> <br> ');
  159. tmp.write('<b> Event Title</b> ')
  160. tmp.write('<input type="text" name="title"> <br> ');
  161. //var title = document.getElementById('title')
  162. tmp.write('<b> Event Desc</b> ');
  163. tmp.write('<input type="text" name="event1"> <br> ');
  164. tmp.write('<b> start time</b> ');
  165. tmp.write('<input type="text" name="start"> <br> ');
  166. tmp.write('<b> end time </b> ');
  167. tmp.write('<input type="text" name="end"> <br> ');
  168. tmp.write('<input type="submit" name="ADD"> <br> ');
  169. tmp.write('<input type="reset" name="CLEAR"> ');
  170. //name = oForm.elements["title"].value;
  171. tmp.write('</form> ')
  172. tmp.write('</body> </html> ');
  173. tmp.close();
  174. }
  175.  
  176. </script>
  177. <style type='text/css'>
  178.  
  179. body {
  180. margin-top: 40px;
  181. text-align: center;
  182. font-size: 14px;
  183. font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
  184. }
  185.  
  186. #calendar {
  187. width: 900px;
  188. margin: 0 auto;
  189. }
  190.  
  191. </style>
  192. </head>
  193. <body>
  194. <div id='calendar'> </div>
  195. </body>
  196. </html>
Reputation Points: 116
Solved Threads: 243
Veteran Poster
hielo is offline Offline
1,123 posts
since Dec 2007
Sep 7th, 2010
0
Re: accessing form fields inside javascript
hi hielo thanks so much for the reply.. when i click on the slot on i got the popup msg with the fields .. but when i give the date , event title, event desc ,start time and end time and click submit.. i am not getting the event on the calander..but when i dont enter any fields in the popup and if i give sumbit i am getting the error msgs which u hav builtin into the code.. could u send me the modified code so that what ever event, start time and endtime which i give must be updated on to the calander
Thank you
Regards
Yopirates
Reputation Points: 10
Solved Threads: 0
Light Poster
yopirates is offline Offline
34 posts
since Feb 2010
Sep 7th, 2010
0
Re: accessing form fields inside javascript
Did you copy and paste the above code onto a BLANK document and saved it as test.html?
It worked for me in Chrome and FF. Hence my comment, "This is a far as I go"
Reputation Points: 116
Solved Threads: 243
Veteran Poster
hielo is offline Offline
1,123 posts
since Dec 2007
Sep 7th, 2010
0
Re: accessing form fields inside javascript
Be sure to test it by opening it directly from the browser, not through the preview option of your editor. If it still does not work, then would expect you to be getting some error message. Are you? What browser are you using?
Reputation Points: 116
Solved Threads: 243
Veteran Poster
hielo is offline Offline
1,123 posts
since Dec 2007
Sep 8th, 2010
0
Re: accessing form fields inside javascript
HI hielo i copied n pasted ur code in a new file called test.html n opened from the browser [google chrome] but when i click on the slot[in the day view] i am able to get the popup window but when i enter event title , start time, end time and click submit ,the popup window is getting closed but other than that event updating is not taking place .So could you see to dis problem n help me in this regard
thankyou
Reputation Points: 10
Solved Threads: 0
Light Poster
yopirates is offline Offline
34 posts
since Feb 2010
Sep 8th, 2010
0
Re: accessing form fields inside javascript
Hielo for me it worked!!! in FF but in chrome didnt thanks so.. much!!So nice that u got me a solution. N Hielo i wanted one more feature to be added that is when i click an already added event i have to get an edit button n should edit the details n upon submit again it has to be saved .
Thankyou
Yopirates
Reputation Points: 10
Solved Threads: 0
Light Poster
yopirates is offline Offline
34 posts
since Feb 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: blur image
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Calender using data from an xml file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC