JavaScript - Call Javascript Function On Form Submit
I have two password fields on a webpage form. If the passwords don't match, I want to display a message. I could use a popup, I could redirect to a page containing the message with another redirect back to the form or, the option I'd like to use, have a hidden table cell in the form containing the message that displays should the form be submitted without matching passwords. If I use the latter, where do I call the javascript function to display the hidden table cell? So in effect, only javascript function would execute if the passwords don't match, the action page itself shouldn't load at all. Can/should this be done on the action page?
Similar TutorialsHey, In the quiz function the form that is generated all compiles correctly, but the submit button only causes the page to refresh. What am I doing wrong? Thank you var c = "1"; //counter var n = [68]; //array that stores unique random numbers var t = "better clear"; var lc = [3]; var uc = [3]; ////////////////////////////////////////////// //The generate() function generates 68 random //unique numbers. ////////////////////////////////////////////// function generate() { var gen = 0; //variable that stores random integer. var j = 1, i = 1; //integers used for loops while (j <= 68) { gen = Math.floor(Math.random()*68+1); for (i = 1; i <= j; i++) { if (n[i] == gen) { break; } else { if (i == j) { n [j] = gen; j++; break; } } } } } ////////////////////////////////////////////// //The rinfo() function reads information that //is pertinent to current question (quality //of triad (t), upper case, and //lower case answers to the question). ////////////////////////////////////////////// function rinfo() { if (n[c] == 1) { t = "a C Major"; lc[3] = "c"; //root uc[3] = "C"; //root lc[2] = "e"; //third uc[2] = "E"; //third lc[1] = "g"; //fifth uc[1] = "G"; //fifth } if (n[c] == 2) { t = "a C Minor"; lc[3] = "c"; //root uc[3] = "C"; //root lc[2] = "eb"; //third uc[2] = "Eb"; //third lc[1] = "g"; //fifth uc[1] = "G"; //fifth } if (n[c] == 3) { t = "a C Augmented"; lc[3] = "c"; //root uc[3] = "C"; //root lc[2] = "e"; //third uc[2] = "E"; //third lc[1] = "g#"; //fifth uc[1] = "G#"; //fifth } if (n[c] == 4) { t = "a C Diminished"; lc[3] = "c"; //root uc[3] = "C"; //root lc[2] = "eb"; //third uc[2] = "Eb"; //third lc[1] = "gb"; //fifth uc[1] = "Gb"; //fifth } if (n[c] == 5) { t = "a F Major"; lc[3] = "f"; //root uc[3] = "F"; //root lc[2] = "a"; //third uc[2] = "A"; //third lc[1] = "c"; //fifth uc[1] = "C"; //fifth } if (n[c] == 6) { t = "a F Minor"; lc[3] = "f"; //root uc[3] = "F"; //root lc[2] = "ab"; //third uc[2] = "Ab"; //third lc[1] = "c"; //fifth uc[1] = "C"; //fifth } if (n[c] == 7) { t = "a F Augmented"; lc[3] = "f"; //root uc[3] = "F"; //root lc[2] = "a"; //third uc[2] = "A"; //third lc[1] = "c#"; //fifth uc[1] = "C#"; //fifth } if (n[c] == 8) { t = "a F Diminished"; lc[3] = "f"; //root uc[3] = "F"; //root lc[2] = "ab"; //third uc[2] = "Ab"; //third lc[1] = "cb"; //fifth uc[1] = "Cb"; //fifth } if (n[c] == 9) { t = "a Bb Major"; lc[3] = "bb"; //root uc[3] = "Bb"; //root lc[2] = "d"; //third uc[2] = "D"; //third lc[1] = "f"; //fifth uc[1] = "F"; //fifth } if (n[c] == 10) { t = "a Bb Minor"; lc[3] = "bb"; //root uc[3] = "Bb"; //root lc[2] = "db"; //third uc[2] = "Db"; //third lc[1] = "f"; //fifth uc[1] = "F"; //fifth } if (n[c] == 11) { t = "a Bb Augmented"; lc[3] = "bb"; //root uc[3] = "Bb"; //root lc[2] = "d"; //third uc[2] = "D"; //third lc[1] = "f#"; //fifth uc[1] = "F#"; //fifth } if (n[c] == 12) { t = "a Bb Diminished"; lc[3] = "bb"; //root uc[3] = "Bb"; //root lc[2] = "db"; //third uc[2] = "Db"; //third lc[1] = "fb"; //fifth uc[1] = "Fb"; //fifth } if (n[c] == 13) { t = "an Eb Major"; lc[3] = "eb"; //root uc[3] = "Eb"; //root lc[2] = "g"; //third uc[2] = "G"; //third lc[1] = "bb"; //fifth uc[1] = "Bb"; //fifth } if (n[c] == 14) { t = "an Eb Minor"; lc[3] = "eb"; //root uc[3] = "Eb"; //root lc[2] = "gb"; //third uc[2] = "Gb"; //third lc[1] = "bb"; //fifth uc[1] = "Bb"; //fifth } if (n[c] == 15) { t = "an Eb Augmented"; lc[3] = "eb"; //root uc[3] = "Eb"; //root lc[2] = "g"; //third uc[2] = "G"; //third lc[1] = "b#"; //fifth uc[1] = "B#"; //fifth } if (n[c] == 16) { t = "an Eb Diminished"; lc[3] = "eb"; //root uc[3] = "Eb"; //root lc[2] = "gb"; //third uc[2] = "Gb"; //third lc[1] = "bbb"; //fifth uc[1] = "Bbb"; //fifth } if (n[c] == 17) { t = "an Ab Major"; lc[3] = "ab"; //root uc[3] = "Ab"; //root lc[2] = "c"; //third uc[2] = "C"; //third lc[1] = "e"; //fifth uc[1] = "E"; //fifth } if (n[c] == 18) { t = "an Ab Minor"; lc[3] = "ab"; //root uc[3] = "Ab"; //root lc[2] = "cb"; //third uc[2] = "Cb"; //third lc[1] = "eb"; //fifth uc[1] = "Eb"; //fifth } if (n[c] == 19) { t = "an Ab Augmented"; lc[3] = "ab"; //root uc[3] = "Ab"; //root lc[2] = "c"; //third uc[2] = "C"; //third lc[1] = "e"; //fifth uc[1] = "E"; //fifth } if (n[c] == 20) { t = "an Ab Diminished"; lc[3] = "ab"; //root uc[3] = "Ab"; //root lc[2] = "cb"; //third uc[2] = "Cb"; //third lc[1] = "eb"; //fifth uc[1] = "Eb"; //fifth } if (n[c] == 21) { t = "a Db Major"; lc[3] = "db"; //root uc[3] = "Db"; //root lc[2] = "f"; //third uc[2] = "F"; //third lc[1] = "a"; //fifth uc[1] = "A"; //fifth } if (n[c] == 22) { t = "a Db Minor"; lc[3] = "db"; //root uc[3] = "Db"; //root lc[2] = "fb"; //third uc[2] = "Fb"; //third lc[1] = "ab"; //fifth uc[1] = "Ab"; //fifth } if (n[c] == 23) { t = "a Db Augmented"; lc[3] = "db"; //root uc[3] = "Db"; //root lc[2] = "f"; //third uc[2] = "F"; //third lc[1] = "a#"; //fifth uc[1] = "A#"; //fifth } if (n[c] == 24) { t = "a Db Diminished"; lc[3] = "db"; //root uc[3] = "Db"; //root lc[2] = "fb"; //third uc[2] = "Fb"; //third lc[1] = "abb"; //fifth uc[1] = "Abb"; //fifth } if (n[c] == 25) { t = "a Gb Major"; lc[3] = "gb"; //root uc[3] = "Gb"; //root lc[2] = "bb"; //third uc[2] = "Bb"; //third lc[1] = "db"; //fifth uc[1] = "Db"; //fifth } if (n[c] == 26) { t = "a Gb Minor"; lc[3] = "gb"; //root uc[3] = "Gb"; //root lc[2] = "bbb"; //third uc[2] = "Bbb"; //third lc[1] = "db"; //fifth uc[1] = "Db"; //fifth } if (n[c] == 27) { t = "a Gb Augmented"; lc[3] = "gb"; //root uc[3] = "Gb"; //root lc[2] = "bb"; //third uc[2] = "Bb"; //third lc[1] = "d"; //fifth uc[1] = "D"; //fifth } if (n[c] == 28) { t = "a Gb Diminished"; lc[3] = "gb"; //root uc[3] = "Gb"; //root lc[2] = "bbb"; //third uc[2] = "Bbb"; //third lc[1] = "dbb"; //fifth uc[1] = "Dbb"; //fifth } if (n[c] == 29) { t = "a B Major"; lc[3] = "b"; //root uc[3] = "B"; //root lc[2] = "d#"; //third uc[2] = "D#"; //third lc[1] = "f#"; //fifth uc[1] = "F#"; //fifth } if (n[c] == 30) { t = "a B Minor"; lc[3] = "b"; //root uc[3] = "B"; //root lc[2] = "d"; //third uc[2] = "D"; //third lc[1] = "f#"; //fifth uc[1] = "F#"; //fifth } if (n[c] == 31) { t = "a B Augmented"; lc[3] = "b"; //root uc[3] = "B"; //root lc[2] = "d#"; //third uc[2] = "D#"; //third lc[1] = "fx"; //fifth uc[1] = "Fx"; //fifth } if (n[c] == 32) { t = "a B Diminished"; lc[3] = "b"; //root uc[3] = "B"; //root lc[2] = "d"; //third uc[2] = "D"; //third lc[1] = "f"; //fifth uc[1] = "F"; //fifth } if (n[c] == 33) { t = "an E Major"; lc[3] = "e"; //root uc[3] = "E"; //root lc[2] = "g#"; //third uc[2] = "G#"; //third lc[1] = "b"; //fifth uc[1] = "B"; //fifth } if (n[c] == 34) { t = "an E Minor"; lc[3] = "e"; //root uc[3] = "E"; //root lc[2] = "g"; //third uc[2] = "G"; //third lc[1] = "b"; //fifth uc[1] = "B"; //fifth } if (n[c] == 35) { t = "an E Augmented"; lc[3] = "e"; //root uc[3] = "E"; //root lc[2] = "g#"; //third uc[2] = "G#"; //third lc[1] = "b#"; //fifth uc[1] = "B#"; //fifth } if (n[c] == 36) { t = "an E Diminished"; lc[3] = "e"; //root uc[3] = "E"; //root lc[2] = "g"; //third uc[2] = "G"; //third lc[1] = "bb"; //fifth uc[1] = "Bb"; //fifth } if (n[c] == 37) { t = "an A Major"; lc[3] = "a"; //root uc[3] = "A"; //root lc[2] = "c#"; //third uc[2] = "C#"; //third lc[1] = "e"; //fifth uc[1] = "E"; //fifth } if (n[c] == 38) { t = "an A Minor"; lc[3] = "a"; //root uc[3] = "A"; //root lc[2] = "c"; //third uc[2] = "C"; //third lc[1] = "e"; //fifth uc[1] = "E"; //fifth } if (n[c] == 39) { t = "an A Augmented"; lc[3] = "a"; //root uc[3] = "A"; //root lc[2] = "c#"; //third uc[2] = "C#"; //third lc[1] = "e#"; //fifth uc[1] = "E#"; //fifth } if (n[c] == 40) { t = "an A Diminished"; lc[3] = "a"; //root uc[3] = "A"; //root lc[2] = "c"; //third uc[2] = "C"; //third lc[1] = "eb"; //fifth uc[1] = "Eb"; //fifth } if (n[c] == 41) { t = "a D Major"; lc[3] = "d"; //root uc[3] = "D"; //root lc[2] = "f#"; //third uc[2] = "F#"; //third lc[1] = "a"; //fifth uc[1] = "A"; //fifth } if (n[c] == 42) { t = "a D Minor"; lc[3] = "d"; //root uc[3] = "D"; //root lc[2] = "f"; //third uc[2] = "F"; //third lc[1] = "a"; //fifth uc[1] = "A"; //fifth } if (n[c] == 43) { t = "a D Augmented"; lc[3] = "d"; //root uc[3] = "D"; //root lc[2] = "f#"; //third uc[2] = "F#"; //third lc[1] = "a#"; //fifth uc[1] = "A#"; //fifth } if (n[c] == 44) { t = "a D Diminished"; lc[3] = "d"; //root uc[3] = "D"; //root lc[2] = "f"; //third uc[2] = "F"; //third lc[1] = "ab"; //fifth uc[1] = "Ab"; //fifth } if (n[c] == 45) { t = "a G Major"; lc[3] = "g"; //root uc[3] = "G"; //root lc[2] = "b"; //third uc[2] = "B"; //third lc[1] = "d"; //fifth uc[1] = "D"; //fifth } if (n[c] == 46) { t = "a G Minor"; lc[3] = "g"; //root uc[3] = "G"; //root lc[2] = "bb"; //third uc[2] = "Bb"; //third lc[1] = "d"; //fifth uc[1] = "D"; //fifth } if (n[c] == 47) { t = "a G Augmented"; lc[3] = "g"; //root uc[3] = "G"; //root lc[2] = "b"; //third uc[2] = "B"; //third lc[1] = "d#"; //fifth uc[1] = "D#"; //fifth } if (n[c] == 48) { t = "a G Diminished"; lc[3] = "g"; //root uc[3] = "G"; //root lc[2] = "bb"; //third uc[2] = "Bb"; //third lc[1] = "db"; //fifth uc[1] = "Db"; //fifth } if (n[c] == 49) { t = "an A# Major"; lc[3] = "a#"; //root uc[3] = "A#"; //root lc[2] = "cx"; //third uc[2] = "Cx"; //third lc[1] = "e#"; //fifth uc[1] = "E#"; //fifth } if (n[c] == 50) { t = "an A# Minor"; lc[3] = "a#"; //root uc[3] = "A#"; //root lc[2] = "c#"; //third uc[2] = "C#"; //third lc[1] = "e#"; //fifth uc[1] = "E#"; //fifth } if (n[c] == 51) { t = "an A# Augmented"; lc[3] = "a#"; //root uc[3] = "A#"; //root lc[2] = "cx"; //third uc[2] = "Cx"; //third lc[1] = "ex"; //fifth uc[1] = "Ex"; //fifth } if (n[c] == 52) { t = "an A# Diminished"; lc[3] = "a#"; //root uc[3] = "A#"; //root lc[2] = "c#"; //third uc[2] = "C#"; //third lc[1] = "e"; //fifth uc[1] = "E"; //fifth } if (n[c] == 53) { t = "a D# Major"; lc[3] = "d#"; //root uc[3] = "D#"; //root lc[2] = "fx"; //third uc[2] = "Fx"; //third lc[1] = "a#"; //fifth uc[1] = "A#"; //fifth } if (n[c] == 54) { t = "a D# Minor"; lc[3] = "d#"; //root uc[3] = "D#"; //root lc[2] = "f#"; //third uc[2] = "F#"; //third lc[1] = "a#"; //fifth uc[1] = "A#"; //fifth } if (n[c] == 55) { t = "a D# Augmented"; lc[3] = "d#"; //root uc[3] = "D#"; //root lc[2] = "fx"; //third uc[2] = "Fx"; //third lc[1] = "ax"; //fifth uc[1] = "Ax"; //fifth } } function first() { alert("W"); } function quiz() { generate(); while (c <= 1) { rinfo(); var output_text = c + ". " + "Enter " + t + " triad."; document.write("<h3>"); document.writeln(output_text); document.write("</h3>"); document.write(" <form align = \"center\">"); document.write(" <input type = \"text\" size = \"2\" name = \"root\" value = \"\" maxlength = \"2\">"); document.write(" <input type = \"text\" size = \"2\" name = \"third\" value = \"\" maxlength = \"2\">"); document.write(" <input type = \"text\" size = \"2\" name = \"fifth\" value = \"\" maxlength = \"2\">"); document.write(" <input type = \"hidden\" name = \"question\" value = 1>"); document.write(" <input type = \"submit\" value=\"Check your answer\" onclick=\"first();\">"); document.write(" <\/form>"); c++; } } The Javascript function change() in not getting called by onClick event of button Click Me ,JavaScript array size has been created in PHP Code: <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script type="text/javascript" language="javascript"> function change() { alert(size[1][0]); } </script> </head> <body> <script language="javascript"> var size = new Array(); var = count; for (count = 0; count < 5; count++) size[count] = new Array(); size[0][0] = 600; size[0][1] = 400; size[1][0] = 300; size[1][1] = 400; size[2][0] = 300; size[2][1] = 400; size[3][0] = 600; size[3][1] = 400; size[4][0] = 300; size[4][1] = 400; </script> <input type="button" value="Click Me" onClick="change()"/> </body> </html> Anything wrong with my coding,any kind support will be apreciated. Thanks, Srinivas. Hi all, I have written the following javascript code which makes a simple calculation and writes between the <span> tags using Inner HTML My code is: Code: <html> <head> <script type="text/javascript"> function hesapla() { kredimiktari = document.hesapla.miktar.value kredivadesi = document.hesapla.vade.value; faiz = document.hesapla.faiz.value; ayliktaksit1 = (kredimiktari * faiz) / kredivadesi; geriodeme1 = kredimiktari * faiz; document.getElementById('ayliktaksit').innerHTML = "<strong>Taksit / Ay :</strong>" + ayliktaksit1; document.getElementById('geriodeme').innerHTML = "<strong>Taksit / Ay :</strong>" + geriodeme1; } </script> </head> <body> <form name="hesapla"> <input type="text" name="miktar" value="Kredi Miktarı" onfocus = "if (this.value == 'Kredi Miktarı') this.value = '';" onblur = "if (this.value == '') this.value = 'Kredi Miktarı';" /> <input type="text" name="vade" value="Kredi Vadesi" onfocus = "if (this.value == 'Kredi Vadesi') this.value = '';" onblur = "if (this.value == '') this.value = 'Kredi Vadesi';" /> <input type="text" name="faiz" value="Faiz Oranı" onfocus = "if (this.value == 'Faiz Oranı') this.value = '';" onblur = "if (this.value == '') this.value = 'Faiz Oranı';" /> <div id="gosterim"><span id="ayliktaksit"></span><span id="geriodeme"></span></div> <input type='button' value='Hesapla' onClick='hesapla()'><br><br> <img src="images/dot2.png" width="180" height="2" alt="dot"/> </form> </body> </html> I am really confused as similar code on Tizag web site works fine. Code: <script type="text/javascript"> function changeText(){ document.getElementById('boldStuff').innerHTML = 'Fred Flinstone'; } </script> <p>Welcome to the site <b id='boldStuff'>dude</b> </p> <input type='button' onclick='changeText()' value='Change Text'/> Could anyone tell me what the wrong thing is about my code Many thanks in advance telmessos I have my events and syntax in the immediate script and they were working fine. But Im trying to move it all into the Script tags and call on them by using the function ID but cant seem to figure it out. here's what I got: <html> <body> <script type="text/javascript"> function txtAmenity() { document.getElementById('divText').innerHTML='Our Luxurious Amenities will Pamper You. Settle into your comfortable accommodations, kick off your shoes, and glance over the vast, peaceful, expanse of the blue, south Atlantic from the privacy of your balcony.'; } </script> <span id="spnAmenity" onmouseover="imgFacility.src= 'images/Amenity.jpg';"txtAmenity()"> Amenities </span> </body> </html> ---------------- Any help here? Hi I have a requirement that from a different domain I will be calling my domain javascript adn calling the fucntion of it directly. I dont want to ask the partner site first download the js and then call the function of it. rather I have seen someplaces they just call the js on links and functions are called directly. in my partner site html I should have something like <a href="http://www.mydomain.com/inc/js/abc.js" >call js </a> and my js will have: function hi(){ alert("hi"); } hi(); so I was expecting that I will see an alert with "hi" but this is not happening. any help mjask I am coding an actionscript app and need to call javascript function in page that embeds the swf file. I am doing this as Action Script 2.0 and am testing in Firefox 1.5 x (flash pluggin version 7) I am getting the following error message: (not part of the error text) re object/embed id/name _DoFSCommand(command, args) (.swf/actionscript call to javascript) in Firefox/1.5.0.3 on Mac OS 10.3x (error text-- from FF javascript console) Error: plugin.SetWindow is not a function Source File: javascript: function jsScriptObject(obj) { this.wrappedJSObject = obj; } jsScriptObject.prototype = { evaluate : function(expression) { return new jsScriptObject(eval(expression)); } }; var plugin = document.embeds['SWFO']; plugin.SetWindow(new jsScriptObject(window),879801055); Line: 1 This set up works in version 10 flash pluggin, as is, in Firefox 3.5.2 Can anyone give me a clue about this? A little further info to possibly save someone some time: I am working on an actionscript 3.0 version that uses externalInterface in Action Script, so I don't need advice to upgrade. I am trying to target older browsers as well as newer ones. Thank you for time and attention; JK hi i'd like to ask how can i ask for a function inside a for loop , if i remove the loop the code works fine but i need it for 10 rows . please help , here is the code PHP Code: $content .=' <table cellspacing="2" cellpadding="2" border="0" align="center" > <SCRIPT LANGUAGE="JavaScript" type="text/JavaScript"> function doCalcAndSubmit() { // get both values kolicina1 = document.forms["vlez1"].kolicina.value; cena1 = document.forms["vlez1"].cena.value; // do some calculation vkupno1 = kolicina1 * cena1; // set the value in the right field document.forms["vlez1"].vkupno.value = vkupno1; } </script> <form id="vlez1" name="vlez1" method="POST" action="index_execute.php" > <tr valign="middle"> <td></td> <td align="center"><b> Sifra : </b></td> <td align="center"><b> Kolicina : </b></td> <td align="center"><b> Cena : </b></td> <td align="center"><b> Vkupno : </b></td> </tr> '; for($t=1;$t<11;$t++) { $content .= ' <tr valign="middle"> <td>'.$t.'.</td> <td><input type="text" id="sifra" autocomplete="off" name="sifra['.$t.']" align="middle" onblur="normalField(this);" onfocus="fireKeyListener_sifra(event); highlightField(this,1);" onkeyup="getList_sifra(event);" size="25" value="" /></td> <td><input type="text" id="kolicina" name="kolicina['.$t.']" align="middle" size="25" ></td> <td><input type="text" id="cena" name="cena['.$t.']" align="middle" size="25" onblur="doCalcAndSubmit();"></td> <td><input type="text" id="vkupno" disabled name="vkupno['.$t.']" align="middle" size="25" ></td> <input type="hidden" name="hidden_data" value="'.$data.'"> </tr>'; } $content .= '<tr> <td></td> <td></td> <td align="center"><input type="submit" id="submit2" name="submit2" value="Potvrdi" ></td> </tr> </form> </table> '; Hi Guys, I am trying to make a change to my website so when someone clicks on the chinese flag image, for example, a function which put the clock forward a few hours. This is what the code I have got at the moment: <td><a href="<? echo $_SERVER[PHP_SELF].'?page='.$page.'&lang=en'; ?>"><img src="images/uk.gif" title="english" border=0></a></td> <td><a href="<? echo $_SERVER[PHP_SELF].'?page='.$page.'&lang=zh'; ?>"><img src="images/ch.gif" title="chinese" onclick="chinatime()" border=0></a></td> <td><a href="<? echo $_SERVER[PHP_SELF].'?page='.$page.'&lang=ja'; ?>"><img src="images/jap.gif" title="japanese" border=0></a></td> <td><a href="<? echo $_SERVER[PHP_SELF].'?page='.$page.'&lang=kk'; ?>"><img src="images/kaz.gif" title="kazakh" border=0></a></td> <td><a href="<? echo $_SERVER[PHP_SELF].'?page='.$page.'&lang='.$most_preferred; ?>">Browser Set</a></td> </tr> <tr> <td colspan="5"> <p class="meta"><span class="date"><script type="text/javascript"> var currentTime = new Date() var minutes = currentTime.getMinutes() var hours = currentTime.getHours() var month = currentTime.getMonth() + 1 var day = currentTime.getDate() var year = currentTime.getFullYear() function chinatime() { hours = hours + 5 } if (minutes < 10) minutes = "0" + minutes document.write(day + "/" + month + "/" + year + " " + hours +":"+minutes) </script> Many Thanks I know I shouldn't be having this problem at this stage. But what have I done wrong? I have my main page, I have my onload page and in that onload page I call a function: And then I get the error message: Fatal error: Call to undefined function OpenChat() The main page code (I've cut out the irrelevant scripts); Code: <?php session_start(); if (!(isset($_SESSION['login']) && $_SESSION['login'] !='')){ header ("Location: Welcome.php"); } $Sfullname=$_SESSION['fullname']; $SMyPId=$_SESSION['MyPId']; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <html> <title></title> <head> <script type="text/javascript"> function OpenChat(Msg){ loadgetdiv(); document.getElementById('<?php echo $Newdiv; ?>').style.display="block"; loadChatComplex('<?php echo $NewThisFile; ?>','<?php echo $Newdiv; ?>',Msg); } </script> <script type="text/javascript"> function loadChatCheck(File,ID,Tile,TID){ loadQuickCheck(File,ID); dodo = setInterval(function(){loadQuickCheck(Tile,TID)},5000); } </script> <script type="text/javascript"> function loadQuickCheck(File,ID){ if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById(ID).innerHTML=xmlhttp.responseText; malaky = setInterval(function(){loadQuickCheck(File,ID)},20000); } } xmlhttp.open("POST",File,true); xmlhttp.send(); } </script> </head> <body onload="loadChatCheck('getCheckNewMessages.php','txtHintCheckNewMessage','getFriendsOnline.php','txtHintShowFriends')"> <div class="mainpage"> <?php include("headermenu.php"); ?> <div id="txtHintShowFriends"></div> <div id="txtHintCheckNewMessage"></div> <br /><br /> </body> </html> AND the onload/getCheckNewMessages.php is PHP Code: <?php session_start(); if (!(isset($_SESSION['login']) && $_SESSION['login'] !='')){ header ("Location: Welcome.php"); } $SMyPId=$_SESSION['MyPId']; include("dbconnect.php"); $result = mysql_query("SELECT COUNT(*) as newchat FROM chat WHERE chattee='{$SMyPId}' AND stat='new'"); $row = mysql_fetch_assoc($result); $total=$row['newchat']; echo 'This is ' . $total .'<br />'; if ($total >=1){ $result = mysql_query("SELECT * FROM chat WHERE chattee='{$SMyPId}' AND stat='new'"); while($row = mysql_fetch_array($result)){ $doormouse=$doormouse . ';' . $row['ChatID']; } $listees=explode(';',$doormouse); foreach($listees as $listor){ echo 'This is ' . $listor . '<br />'; $result = mysql_query("SELECT * FROM chat INNER JOIN allusers ON chat.chatter=allusers.PId WHERE chat.ChatID='{$listor}' "); while($row = mysql_fetch_array($result)){ echo "{$SMyPId};{$row['chatter']};{$row['fullname']};{$row['ref']}"; } echo $battlebox . '<br />'; $steptoe=OpenChat($battlebox); } $sql="UPDATE chat set stat='' WHERE ChatID='{$chatID}' "; mysql_query($sql,$con) or die(mysql_error()); } ?> Needless to say I am trying to create an instant chat. Is there a way to call javascript functions based on the text between a span element? In other words if I have <span id="mySpan">Bronze</span> then it will call a javascript function but if I have <span id="mySpan">Silver</span> then it will call a different function? Thanks! which is the real difference between: <script> alert('hello'); </script> and <script> function hi() {alert('hello');} </script> thanks in advance makerjoe Hi , I am inserting an image into a span tag by click on button and resize the image using resize_image_height_weight function. I am using two function to do this task. setImage setImage_w3Validation setImage function resize the image but fail on w3validation on my webpage( As per w3c there is no attribute onload for image tag.) To fix out this issue I am using setImage_w3Validation function which pass on w3validation but unable to call resize_image_height_weight function. My purpose is to resize the image. Kindly suggest me how to do it? <html> <head> <script TYPE="text/javascript" language="javascript"> function resize_image_height_weight(id, hgt, wdth){ //alert(id); Obj=document.getElementById(id); myImage = new Image(); myImage.src = Obj.src; var heights = myImage.height; var widths = myImage.width; // alert("Height=>" + heights + " Width=> " + widths); if(heights > hgt || widths > wdth) { if(heights > widths) { var temp = heights/hgt; var new_width = widths / temp; new_width = parseInt(new_width); heights = hgt; widths = new_width; } else { var temp = widths/wdth; var new_height = heights / temp; new_height = parseInt(new_height); heights = new_height; widths = wdth; } } Obj.height = heights; Obj.width = widths; } function setImage(){ document.getElementById("IM0").innerHTML ="<center><img src=\"http://www.google.co.in/intl/en_com/images/srpr/logo1w.png\" id=\"img1\" alt=\"\" height=\"125\" width=\"125\" onload=\"resize_image_height_weight('img1',125,125);\"><\/center>"; } function setImage_w3Validation(){ document.getElementById("IM1").innerHTML ="<center><img src=\"http://www.google.co.in/intl/en_com/images/srpr/logo1w.png\" id=\"img2\" alt=\"\" height=\"125\" width=\"125\"><script type=\"text/javascript\">document.getElementById('img2').onload = function(){resize_image_height_weight('i12',125,125);};<\/SCRIPT><\/center>"; //I wanna to do the task using this one function to resize img for w3validation } function clear_page(){ document.getElementById("IM0").innerHTML =""; document.getElementById("IM1").innerHTML =""; } </script> </head> <body> <div class="img3"><span id="IM0"></span></div> <div class="img3"><span id="IM1"></span></div> <input type="button" name="btn1" value="Image Onload W3C Fail" onclick="setImage();"> <input type="button" name="btn2" value="Image Onload W3C Pass" onclick="setImage_w3Validation();"> <input type="button" name="btn2" value="Clear" onclick="clear_page();"> </body> </html> Newbie developer/sys admin working on a SalesForce platform here, so excuse my ignorance with terminology. This is a file upload problem. The current code first inserts a record into Salesforce, THEN posts to Amazon S3. The record is just a unique URL that is a link to where Amazon houses the file. Problem here is that sometimes users cancel/close the page before form submits, but the record is already created. Now, I need to reverse this so that it first posts to Amazon S3, then inserts the "link" record. Is there a way to evaluate if a post is successful THEN trigger the apex method OR a second javascript function? Relevant bits he (if we need the entire page, i can paste that too, but alot of it is apex and salesforce specific) Code: <script type="text/javascript"> var sendFile = false; var ProgressImage = document.getElementById('{!$Resource.ajaxloader}'); document.getElementById('{!$Component.hiddenServerURL}').value = '{!$Api.Enterprise_Server_URL_140}'; function setFileName(file) { var f = file.replace(/\\/g, ""); f = f.replace(/C\:fakepath/g, ""); <!--Required for IE8--> document.s3Form.key.value = "{!CustomerName}/{!OrderName}/" + f; document.getElementById('{!$Component.fileName}').value = f; suffix = f.lastIndexOf(".") + 1; contentType = f.slice(suffix); document.getElementById('{!$Component.contentType}').value = contentType; } function setFileType(type) { document.getElementById('{!$Component.fileType}').value = type; } function checkFile() { if (document.s3Form.file.value=="") { alert("Please, select a file."); return false; } else if (document.s3Form.fType.value=="--None--") { alert("Please, select a file type."); return false; } else { loadSubmit(); insertFile(); sendFile = true; } } function submitFile() { if(sendFile = false) { return false; } else { document.s3Form.submit(); } } function loadSubmit() { document.getElementById("progress").style.visibility = "visible"; setTimeout(function(){ProgressImage.src = ProgressImage.src},100); return true; } function cancelFile() { window.location.href = "{!$Setup.companyInfo__c.colliers__c}"; } function completeFile() { completeOrder(); } </script> apex:actionFunction on this page, javascript can directly make a call to the class and invoke a method there. Code: <apex:actionFunction name="insertFile" action="{!insertFile}" oncomplete="submitFile();return false;"/> the pertinent "html" (visualforce) for this page Code: <apex:pageBlockButtons location="bottom"> <input class="btn" type="button" value="Upload File" onClick="checkFile();return false;"/> <input class="btn" type="button" value="Cancel" onClick="cancelFile();return false;"/> <input class="btn" type="button" value="Complete Order" onClick="completeFile();return false;"/> </apex:pageBlockButtons> This piece is from the class/extension: Code: //SF File insert on an object (passed from page) public PageReference insertFile() { this.file.Name = fileName; this.file.Type__c = fileType; this.file.Content__c = contentType; insert this.file; return null; } Ideally, i would like to change the checkFile() function to something like the below - but haven't had much luck in researching how to accomplish this... Code: function checkFile() { if (document.s3Form.file.value=="") { alert("Please, select a file."); return false; } else if (document.s3Form.fType.value=="--None--") { alert("Please, select a file type."); return false; } else { loadSubmit(); if(document.seForm.submit() = true) insertFile(); } } UPDATE: I just learned that S3 should return a "success_action_status" if the post is successful - how do i use this to achieve what I need? (http://docs.amazonwebservices.com/Am...POSTForms.html) I've literally tried everything. Read 26 tutorials, interchanged code, etc. My validation functions all work. My AJAX functions work (tested manually using servlet URL's). The second servlet validates the reCaptcha form that's generated on my webpage. After the form is validated, even if everything's correct, nothing happens upon clicking submit. I even have an alert pop up if with the captcha result, just for middle-layer debugging purposes. I want to do all of my validation clientside; none serverside. However, going to be tough if I can't get my god damn form to submit. I've been puzzled by this for close to 36 hours straight. I can't see, and I'm going to get some rest and hope that there is some useful insight on my problem when I return. html form: Code: <form id="f1" name="form1" onsubmit="validate_form(this); return false;" action="register" method="post"> <table cellspacing="5" style="border: 2px solid black;"> <tr> <td valign="top"> <table cellspacing="5"> <tr> <td>*First name</td> <td align="right"><span id="valid_one"></span></td> <td><input type="text" style="width: 320px;" id="fn" name="fn" onBlur="validate_one();"></td> </tr> <tr> <td align="left">*Last name</td> <td align="right"><span id="valid_two"></span></td> <td><input type="text" style="width: 320px;" id="ln" name="ln" onBlur="validate_two();"></td> </tr> <tr> <td align="left">*Email address</td> <td align="right"><span id="result"></span></td> <td><input type="text" style="width: 320px;" id="mailfield" name="email" onBlur="startRequest();"></td> </tr> <tr> <td align="left">*Phone number</td> <td align="right"><span id="valid_three"></span></td> <td><input type="text" style="width: 320px;" id="pn" name="pn" onBlur="validate_three();"></td> </tr> <tr> <td align="left">*City/Town</td> <td align="right"><span id="valid_four"></span></td> <td><input type="text" style="width: 320px;" id="c" name="c" onBlur="validate_four();"></td> </tr> <tr> <td></td> <td></td> <td> <select name="s"> <option value="AL">Alabama <option value="AK">Alaska <option value="AZ">Arizona <option value="AR">Arkansas <option value="CA">California <option value="CO">Colorado <option value="CT">Connecticut <option value="DE">Delaware <option value="FL">Florida <option value="GA">Georgia <option value="HI">Hawaii <option value="ID">Idaho <option value="IL">Illinois <option value="IN">Indiana <option value="IA">Iowa <option value="KS">Kansas <option value="KY">Kentucky <option value="LA">Louisiana <option value="ME">Maine <option value="MD">Maryland <option value="MA">Massachusetts <option value="MI">Michigan <option value="MN">Minnesota <option value="MS">Mississippi <option value="MO">Missouri <option value="MT">Montana <option value="NE">Nebraska <option value="NV">Nevada <option value="NH">New Hampshire <option value="NJ">New Jersey <option value="NM">New Mexico <option value="NY">New York <option value="MC">North Carolina <option value="ND">North Dakota <option value="OH">Ohio <option value="OK">Oklahoma <option value="OR">Oregon <option value="PA">Pennsylvania <option value="RI">Rhode Island <option value="SC">South Carolina <option value="SD">South Dakota <option value="TN">Tennessee <option value="TX">Texas <option value="UT">Utah <option value="VT">Vermont <option value="VA">Virginia <option value="WA">Washington <option value="WV">West Virginia <option value="WI">Wisconsin <option value="WY">Wyoming </select> </td> </tr> <tr> <td> <br> </td> </tr> <tr> <td></td> <td></td> <td><span id="error"></span></td> </tr> <tr> <td valign="top">*Anti-Spam Verification</td> <td></td> <td id="reCaptcha"></td> </tr> </table> </td> <td valign="top"> <table cellspacing="5"> <tr> <td align="left">*Affiliation</td> <td align="right"><span id="valid_five"></span></td> <td><input type="text" style="width: 320px;" id="affl" name="affl" onBlur="validate_five();"></td> </tr> <tr> <td align="left">*Research Area:</td> <td align="right"><span id="valid_six"></span></td> <td><input type="text" style="width: 320px;" id="ra" name="ra" onBlur="validate_six();"></td> </tr> <tr> <td valign="top" align="left">*Research Overview</td> <td align="right"><span id="valid_seven"></span></td> <td><textarea cols="38" rows="6" id="ro" name="ro" onKeyDown="limitText(this.form.ro,this.form.countdown,500)" onKeyUp="limitText(this.form.ro,this.form.countdown,500)" onBlur="validate_seven();"></textarea></td> </tr> <tr> <td></td> <td></td> <td><font size="1">You have <input readonly type="text" name="countdown" size="1" value="500"> characters remaining.</font></td> </tr> <tr> <td align="left">*Talk Availability</td> <td></td> <td> <input type="radio" name="ta" value="In person">In person <input type="radio" name="ta" value="Online">Online <input type="radio" name="ta" value="Both" checked>Both </td> </tr> <tr> <td align="left" valign="top">Links</td> <td></td> <td> <table id="linkTable" border="0"> <td><input type="text" style="width: 320px;" name="link"></td> <td><div id="result"></div></td> </table> </td> <td align="left" valign="top"><input type="button" value="Add Link" onclick="addLink('linkTable')"></td> </tr> <tr> <td></td> <td><span style="color: red;"></span></td> </tr> </table> </td> </tr> </table> <br /> <input type="submit" id="submit" name="submit" value="Submit Form"> </form> Javascript file: Code: /* * script.js - ajax and table functions */ var xmlHttp; // global instance of XMLHttpRequest var xmlHttp2; // second for captcha functions var validAjax = new Boolean(); var validCaptcha = new Boolean(); var valid_one = new Boolean(); var valid_two = new Boolean(); var valid_three = new Boolean(); var valid_four = new Boolean(); var valid_five = new Boolean(); var valid_six = new Boolean(); var valid_seven = new Boolean(); function init() { showRecaptcha('reCaptcha'); // Separate booleans for AJAX funcs validAjax = false; validCaptcha = false; // Booleanse for fields that don't require servlet validation valid_one = false; valid_two = false; valid_three = false; valid_four = false; valid_five = false; valid_six = false; valid_seven = false; } function showRecaptcha(element) { Recaptcha.create("6Le1a8ESAAAAAGtxX0miZ2bMg0Wymltnth7IG-Mj", element, {theme: "red", callback: Recaptcha.focus_response_field}); } function validate_form() { if (valid_one && valid_two && valid_three && valid_four && validEmail) { startCaptchaRequest(); if (validCaptcha) { return true; } } else { alert("Submission contains errors. Please fill out all required fields before submitting."); return false; } } function validate_one() { if (document.getElementById("fn").value == 0) { valid_one = false; document.getElementById("valid_one").innerHTML = "No"; } else { valid_one = true; document.getElementById("valid_one").innerHTML = ""; } } function validate_two() { if (document.getElementById("ln").value == 0) { valid_two = false; document.getElementById("valid_two").innerHTML = "No"; } else { valid_two = true; document.getElementById("valid_two").innerHTML = ""; } } function validate_three() { if (document.getElementById("pn").value == 0) { valid_three = false; document.getElementById("valid_three").innerHTML = "No"; } else { valid_three = true; document.getElementById("valid_three").innerHTML = ""; } } function validate_four() { if (document.getElementById("c").value == 0) { valid_four = false; document.getElementById("valid_four").innerHTML = "No"; } else { valid_four = true; document.getElementById("valid_four").innerHTML = ""; } } function validate_five() { if (document.getElementById("affl").value == 0) { valid_five = false; document.getElementById("valid_five").innerHTML = "No"; } else { valid_five = true; document.getElementById("valid_five").innerHTML = ""; } } // //function validate_six() { // if (document.getElementById("ra").value == 0) { // valid_six = false; // document.getElementById("valid_six").innerHTML = "No"; // } // else { // valid_six = true; // document.getElementById("valid_six").innerHTML = ""; // } //} // //function validate_seven() { // if (document.getElementById("ro").value == 0) { // valid_seven = false; // document.getElementById("valid_seven").innerHTML = "No"; // } // else { // valid_seven = true; // document.getElementById("valid_seven").innerHTML = ""; // } //} function addLink(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var cell = row.insertCell(0); var element1 = document.createElement("input"); element1.type = "text"; element1.name = "link" + rowCount; element1.style.width = "320px"; cell.appendChild(element1); } function limitText(limitField, limitCount, limitNum) { if (limitField.value.length > limitNum) { limitField.value = limitField.value.substring(0, limitNum); } else { limitCount.value = limitNum - limitField.value.length; } } function createXmlHttpRequest() { if(window.ActiveXObject) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } else if(window.XMLHttpRequest) { xmlHttp=new XMLHttpRequest(); } } function startRequest() { createXmlHttpRequest(); var param1 = document.getElementById('mailfield').value; if (param1 == "") { validEmail = false; document.getElementById("result").innerHTML = "Blank"; } else { xmlHttp.open("GET", "http://localhost:1979/PolarSpeakers/servlet/mailCheck.do?e=" + param1, true) xmlHttp.onreadystatechange = handleStateChange; xmlHttp.send(null); } } function handleStateChange() { if(xmlHttp.readyState==4) { if(xmlHttp.status==200) { var message = xmlHttp.responseXML .getElementsByTagName("valid")[0] .childNodes[0].nodeValue; if (message == "Unregistered") { validEmail = true; document.getElementById("result").style.color = "green"; } else { validEmail = false; document.getElementById("result").style.color = "red"; } document.getElementById("result").innerHTML = message; } else { alert("Error checking e-mail address - " + xmlHttp.status + " : " + xmlHttp.statusText); } } } function createCaptchaRequest() { if(window.ActiveXObject) { xmlHttp2=new ActiveXObject("Microsoft.XMLHTTP"); } else if(window.XMLHttpRequest) { xmlHttp2=new XMLHttpRequest(); } } function startCaptchaRequest() { alert('made it to captcha requeswt'); createCaptchaRequest(); var param1 = Recaptcha.get_challenge(); var param2 = Recaptcha.get_response(); xmlHttp2.open("POST", "http://localhost:1979/PolarSpeakers/servlet/captchaCheck.do?c=" + param1 + "&r=" + param2, true) xmlHttp2.onreadystatechange = handleStateChangeCaptcha; xmlHttp2.send(null); } function handleStateChangeCaptcha() { if(xmlHttp2.readyState==4) { if(xmlHttp2.status==200) { var message = xmlHttp2.responseXML .getElementsByTagName("result")[0] .childNodes[0].nodeValue; if (message == "Valid") { alert("captcha valid"); validCaptcha = true; } else { document.getElementById("error").innerHTML = message; validCaptcha = false; } } else { alert("Error checking captcha validity - " + xmlHttp2.status + " : " + xmlHttp2.statusText); } } } I have a simple form and am validating onchange and need a final validation onsubmit. I am displaying a message to the right of the inputbox on error. I'm trying to keep this at DOM 1 compatible and not use any framework. HTML Code: <form id = "myForm" action = "" onsubmit = "return validateForm(this);"> <table class = "table-submit" border = "0"> <tr> <td> Username: </td> <td> <input type = "text" id = "username" size = "30" maxlength = "30" onchange = "validateUsername(this, 'msgUsername')" /> </td> <td id = "msgUsername"> </td> </tr> <tr> <td> Password: </td> <td> <input type = "password" id = "password" size = "30" maxlength = "30" onchange = "validatePassword(this, 'msgPassword')" /> </td> <td id = "msgPassword"> </td> </tr> <tr> <td> </td> <td> <input type = "submit" value = "Submit" /> <input type = "reset" value = "Clear" /> </td> </tr> </table> </form> JavaScript Code: function validateUsername(myItem, myElement) { var dom = document.getElementById(myElement); if (myItem.value.length < 3) { dom.innerHTML = " Username needs to be a minimum of 3 characters! "; return false; } else { dom.innerHTML = ""; return true; } } function validatePassword(myItem, myElement) { var dom = document.getElementById(myElement); if (myItem.value.length < 5) { dom.innerHTML = " Password needs to be a minimum of 5 characters! "; return false; } else { dom.innerHTML = ""; return true; } } function validateForm (itm) { // kind of stuck here... } As you may of noticed, I am a bit stuck on my validateForm() function. The code validates on each inputbox onchange event. Not sure what is the best way to go from here. I thought about doing an If for my both single input box validation, but I would need to send each parameters which is what i was trying to avoid by using this. Would like some suggestions. I am not familiar with javascript only html, but I have researched this problem and found some solutions, but I am unsure what to do with them. I have an html checkbox form that lists book titles. The user will click on the checkbox next to the titles that interest them. Then when they click submit, I want a pop-up box to appear with the titles they selected in a printable list. I found this javascript code: Code: <script langauge="javascript" type="text/javascript"> function openPreview() { var myWin = window.open ("popup.htm","myWindowName","width=500,height=350"); myWin.focus(); } </script> Then here is my html form code: Code: <form action="" form id= "myInput"> <table width="523"> <tr><td width="33"> <input type="checkbox" name="product" value="Ironman"></td> <td width="229"><div align="left">Ironman</div></td> <td width="174">Chris Crutcher </td> <td width="56" align="right"> </td></tr> <tr><td><input type="checkbox" name="product" value="Staying Fat for Sarah Byrnes"> <th><div align="left">Staying Fat for Sarah Byrnes </div></th> <td>Chris Crutcher </td> <td align="right"><tt>Realism</tt></td> </tr> <tr><td><input type="checkbox" name="product" value="The Watsons Go to Birmingham"> <th><div align="left">The Watsons Go to Birmingham </div></th> <td>Chrisopher Paul Curtis </td> <td align="right"> </td> </tr> </table> <input type="button" id="btnPreview" name="btnPreview" value="Preview" onclick="openPreview()" /> </form> Then on the popup.htm page I have this code Code: <script language="javascript" type="text/javascript"> document.write(window.opener.document.getElementById("myInput").value); </script> This code has worked for me when the form is a textarea or a label, but I don't know how to use it with a checkbox form. I know that labeling the form "my input" only works for textarea or labels, so I understand why the pop-up menu says undefined. What do I need to do to get the checkbox data to appear. I have created a php script that POSTs to another page sendmail.php which then redirects to a thanks/successful page. Is it possible to have the form submit and return a thank you message on the same page. basically submit the form without reloading. I want to use Javascript to submit a form - without filling the form in physically Is this possible? Let's say a web page has a form that submit First Name and Last Name to the next page Instead of filling in the form and hitting submit, can I submit the data in variables and call the next page somehow using Javascript? Thanks OM Is there a way to stop a form submit after hitting submit? Refresh wouldn't realy be an option. Is abort() what I'm looking for?
|