Help modify some JavaScript/HTML

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: May 2005
Posts: 182
Reputation: alpha_foobar is an unknown quantity at this point 
Solved Threads: 3
alpha_foobar's Avatar
alpha_foobar alpha_foobar is offline Offline
Junior Poster

Re: Help modify some JavaScript/HTML

 
1
  #11
Jun 22nd, 2006
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head></head>
  3. <body>
  4. <script language="javascript" type="text/javascript">
  5. var set_action = "";
  6. var set_path = "images/";
  7. var set_id="<!--%ID%-->";
  8. var set_spacer = "spacer.gif";
  9. var set_scroll = "f0.gif";
  10. var set_thumb = "f1.gif";
  11. var set_rate1 = "1.gif";
  12. var set_rate2 = "2.gif";
  13. var set_rate3 = "3.gif";
  14. var set_rate4 = "4.gif";
  15. var set_rate5 = "5.gif";
  16. var set_mark1 = "1";
  17. var set_mark2 = "2";
  18. var set_mark3 = "3";
  19. var set_mark4 = "4";
  20. var set_mark5 = "5";
  21. var set_text = "";
  22. var set_submit = "Vote";
  23. //SETTINGS END
  24. var gotkl = 0;
  25. var path = set_path;
  26. var index = 0;
  27. var firstTime = true;
  28. var img_f = new Array();
  29. img_f[0] = new Image();
  30. img_f[1] = new Image();
  31. img_f[0].src= path + set_scroll;
  32. img_f[1].src= path + set_thumb;
  33. //Files with images
  34. var img_p = new Array();
  35. img_p[1] = new Image();
  36. img_p[2] = new Image();
  37. img_p[3] = new Image();
  38. img_p[4] = new Image();
  39. img_p[5] = new Image();
  40. set_spacer =path + set_spacer;
  41. img_p[1].src=path + set_rate1;
  42. img_p[2].src=path + set_rate2;
  43. img_p[3].src=path + set_rate3;
  44. img_p[4].src=path + set_rate4;
  45. img_p[5].src=path + set_rate5;
  46.  
  47. function imgonload() {
  48. document.id_pn.src = img_p[5].src;
  49. document.id_pn1.src = img_p[5].src;
  50. }
  51.  
  52. flg = (document.all) ? 0 : 1;
  53. var obj;
  54. var dx,dy;
  55. var flag = false;
  56. var flag1 = false;
  57.  
  58. function mousedown(ev)
  59. {
  60. if (flg)
  61. {
  62. X=ev.clientX;
  63. Y=ev.clientY;
  64. return false;
  65. }
  66. else
  67. {
  68. X=event.clientX;
  69. Y=event.clientY;
  70. }
  71. }
  72. function mousemove(ev)
  73. {
  74. if (flag)
  75. {
  76.  
  77. if (flg)
  78. {
  79. X2=ev.clientX;
  80. Y2=ev.clientY;
  81. }
  82. else
  83. {
  84. X2=event.clientX;
  85. Y2=event.clientY;
  86. }
  87. dy=Y2-Y;
  88. var dh=document.id_spacer.height+dy;
  89.  
  90. if (dh>-1 && document.id_spacer.height+dy<document.id_pn.height-7) {
  91.  
  92. document.id_spacer.height = document.id_spacer.height+(Y2-Y);
  93. Y=Y2;
  94. };
  95. if (dh<=-1)
  96. {
  97. document.id_spacer.height=1;
  98. }
  99. if (dh>=document.id_pn.height-7)
  100. {
  101. document.id_spacer.height=document.id_pn.height-8;
  102. }
  103. var mark=Math.floor(document.id_spacer.height/(document.id_pn.height/5));
  104. //alert(mark);
  105. mark=5-mark;
  106. document.id_pn.src = img_p[mark].src
  107. document.post_form.rate.value=mark;
  108. //window.status=mark;
  109. return false;
  110. }
  111. else if (flag1)
  112. {
  113.  
  114. if (flg)
  115. {
  116. X2=ev.clientX;
  117. Y2=ev.clientY;
  118. }
  119. else
  120. {
  121. X2=event.clientX;
  122. Y2=event.clientY;
  123. }
  124. dy=Y2-Y;
  125. var dh=document.id_spacer1.height+dy;
  126.  
  127. if (dh>-1 && document.id_spacer1.height+dy<document.id_pn1.height-7) {
  128.  
  129. document.id_spacer1.height = document.id_spacer1.height+(Y2-Y);
  130. Y=Y2;
  131. };
  132. if (dh<=-1)
  133. {
  134. document.id_spacer1.height=1;
  135. }
  136. if (dh>=document.id_pn1.height-7)
  137. {
  138. document.id_spacer1.height=document.id_pn1.height-8;
  139. }
  140. var mark=Math.floor(document.id_spacer1.height/(document.id_pn1.height/5));
  141. //alert(mark);
  142. mark=5-mark;
  143. document.id_pn1.src = img_p[mark].src
  144. document.post_form.rate2.value=mark;
  145. //window.status=mark;
  146. return false;
  147. }
  148. }
  149. function mouseup()
  150. {
  151. obj = null;
  152. flag = false;
  153. flag1 = false;
  154. }
  155.  
  156. if (flg)
  157. {
  158. document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
  159. }
  160. document.onmousedown = mousedown;
  161. document.onmousemove = mousemove;
  162. document.onmouseup = mouseup;
  163. document.write(
  164. "<table border='0' cellspacing='0' cellpadding='0' width='100px'>"+
  165. " <tr>"+
  166. " <td align='center'>"+
  167. " <img align='middle' name='id_pn'>"+
  168. " </td>"+
  169. " <td id='scroll_cell' align='center' valign='top' width='20' background='"+img_f[0].src+"'>"+
  170. "<table border=0 cellspacing='0' cellpadding='0'><tr><td><img border=0 name='id_spacer' width='20' height='0' src='"+set_spacer+"'></td></tr><tr><td><img width='20' height='8' border='0' id='id_pil' src='"+img_f[1].src+" 'style='cursor : hand;' onMouseDown='flag = true;' ></td></table>"+
  171. " </td>"+
  172. " </tr>"+
  173. " <tr>"+
  174. " <td align='center'>"+
  175. " <img align='middle' name='id_pn1'>"+
  176. " </td>"+
  177. " <td id='scroll_cell1' align='center' valign='top' width='20' background='"+img_f[0].src+"'>"+
  178. "<table border=0 cellspacing='0' cellpadding='0'><tr><td><img border=0 name='id_spacer1' width='20' height='0' src='"+set_spacer+"'></td></tr><tr><td><img width='20' height='8' border='0' id='id_pil1' src='"+img_f[1].src+" 'style='cursor : hand;' onMouseDown='flag1 = true;' ></td></table>"+
  179. " </td>"+
  180. " </tr>"+
  181. "<form action='"+set_action+"' method='post' name='post_form'>"+
  182. " <tr>"+
  183. " <td colspan='2' style='padding: 2px' align='center'>"+
  184. " <input style='width:40%' type='submit' value='"+set_submit+"' onclick=\"javascript:alert('rate.value='+document.post_form.rate.value+', rate2.value='+document.post_form.rate2.value)\">"+
  185. " <input type='hidden' name='ID' value='"+set_id+"'><input type='hidden' name='rate' value='5'><input type='hidden' name='rate2' value='5'>"+
  186. " </td>"+
  187. " </tr></form></table>");
  188. imgonload();
  189.  
  190. </script></body></html>

I disagree. This is what you call the copy and paste technique... the code is now double the ugliness, a nicer solution would take a little more typing. But a little less total code.

The use of the element name (to locate dom elements) isn't really supported across browsers, it works now in Firefox, because most pages are written for IE. But I don't know how supported it is across other browsers.

Cheers.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 279
Reputation: J_Search is an unknown quantity at this point 
Solved Threads: 6
J_Search J_Search is offline Offline
Posting Whiz in Training

Re: Help modify some JavaScript/HTML

 
0
  #12
Jun 22nd, 2006
Thanks for your help, and putting up with me.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 182
Reputation: alpha_foobar is an unknown quantity at this point 
Solved Threads: 3
alpha_foobar's Avatar
alpha_foobar alpha_foobar is offline Offline
Junior Poster

Re: Help modify some JavaScript/HTML

 
0
  #13
Jun 23rd, 2006
That's cool, I get bored at work. as a rule of thumb, the easier it is for people to access the problem, the easier it is for them to help.

If I can glance at the code and see I can paste it into a webpage without editing it, I will, even if I have no idea what the problem is! So what you did with a zip was handy, as the images are rather important sometimes too.

Everything you have mentioned is doable, as always, a problem has many solutions.

Have fun.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 279
Reputation: J_Search is an unknown quantity at this point 
Solved Threads: 6
J_Search J_Search is offline Offline
Posting Whiz in Training

Re: Help modify some JavaScript/HTML

 
0
  #14
Jun 23rd, 2006
alpha_foobar,

I hate to beat a dead horse, but...

I created rater2 with mouseover rather than mouse drag. Do you think this will work too? I only found one problem. If you mouseover and click on one of the numberes, then mouse over the link to display the rating, it will display the javascript alert twice. If I used
<input type='hidden' name='rate' value='"+rate+"'> do you think it will cause an issue with double votes like the javascript alert has?

Thanks,
Attached Files
File Type: zip rater2.zip (5.8 KB, 1 views)
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum


Views: 4400 | Replies: 13
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC