944,007 Members | Top Members by Rank

Ad:
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Jun 22nd, 2006
1

Re: Help modify some JavaScript/HTML

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.
Reputation Points: 20
Solved Threads: 5
Junior Poster
alpha_foobar is offline Offline
182 posts
since May 2005
Jun 22nd, 2006
0

Re: Help modify some JavaScript/HTML

Thanks for your help, and putting up with me.
Reputation Points: 27
Solved Threads: 6
Posting Whiz in Training
J_Search is offline Offline
284 posts
since Aug 2005
Jun 23rd, 2006
0

Re: Help modify some JavaScript/HTML

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.
Reputation Points: 20
Solved Threads: 5
Junior Poster
alpha_foobar is offline Offline
182 posts
since May 2005
Jun 23rd, 2006
0

Re: Help modify some JavaScript/HTML

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, 19 views)
Reputation Points: 27
Solved Threads: 6
Posting Whiz in Training
J_Search is offline Offline
284 posts
since Aug 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

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: Compiler
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Unsolved dropdown menu





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


Follow us on Twitter


© 2011 DaniWeb® LLC