JavaScript - Send Value To Javascript Function
Hello,
In the following code i'm trying to check if the value of the text field is exist in the array. the problem that the function dose not accept the the value(node.value) from the text field. Code: <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Text Validation</title> <script type="text/javascript" language="javascript"> Array.prototype.inArray = function (value) { // Returns true if the passed value is found in the // array. Returns false if it is not. alert(value); var i; for (i=0; i < this.length; i++) { if (this[i] == value) { return true; } } return false; }; function cal(xx) { var node_list = document.getElementsByTagName('input'); arr = new Array(""); for (var i = 0; i < node_list.length; i++) { var node = node_list[i]; ///alert(node_list.length); // alert(node.value); arr.push(node.value) } alert(xx.length); //var arr= new Array(1,2,3,4,5,6,7,8,9,10); if(xx.length!=0) { if(arr.inArray(xx)) { alert("Your value is found in the Array"); } else { alert("Your value is not found in the Array"); } } } </script> </head> <body> <form id="text_validation" name="text_validation" action="" method="post"> <table width="600" border="1"> <tr> <td><label for="abc_text_1" id="abc_text_1_lb">Text 1</label> </td> <td>:</td> <td><input type="text" id="abc_text_1" name="abc_text_1" onblur="return cal(this.value);" /></td> </tr> <tr> <td><label for="cde_text_2" id="cde_text_2_lb">Text 2</label> </td> <td>:</td> <td><input type="text" id="cde_text_2" name="cde_text_2" value="abc" /></td> </tr> <tr> <td><label for="fgh_text_3" id="fgh_text_3_lb">Text 3</label> </td> <td>:</td> <td><input type="text" id="fgh_text_3" name="fgh_text_3" value="abcaaaaa" onblur="return testvalidation(fgh_text_3);" /></td> </tr> <tr> <td><label for="ijk_text_4" id="ijk_text_4_lb">Text 4</label> </td> <td>:</td> <td><input type="text" id="ijk_text_4" name="ijk_text_4" onblur="return testvalidation(ijk_text_4);" /></td> </tr> <tr> <td><label for="lmn_text_5" id="lmn_text_5_lb">Text 5</label> </td> <td>:</td> <td><input type="text" id="lmn_text_5" name="lmn_text_5" onblur="return testvalidation(lmn_text_5);" /></td> </tr> <tr> <td><label for="opq_text_6" id="opq_text_6_lb">Text 6</label> </td> <td>:</td> <td><input type="text" id="opq_text_6" name="opq_text_6" onblur="return testvalidation(opq_text_6);" /></td> </tr> <tr> <td><label for="rst_text_7" id="rst_text_7_lb">Text 7</label> </td> <td>:</td> <td><input type="text" id="rst_text_7" name="rst_text_7" /></td> </tr> <tr> <td><label for="uvw_text_8" id="uvw_text_8_lb">Text 8</label> </td> <td>:</td> <td><input type="text" id="uvw_text_8" name="uvw_text_8" /></td> </tr> <tr> <td><label for="xyz_text_9" id="xyz_text_9_lb">Text 9</label> </td> <td>:</td> <td><input type="text" id="xyz_text_9" name="xyz_text_9" /></td> </tr> <tr> <td><label for="klm_text_0" id="klm_text_0_lb">Text 10</label> </td> <td>:</td> <td><input type="text" id="klm_text_0" name="klm_text_0" value="10" /></td> </tr> </table> </form> </body> </html> Similar TutorialsI'm trying to make a jQuery slider, and I want the user (the person who installs it on their site) to be able to specify options easily. I know the Nivo slider does it from within the $(document).ready() event, but I can't figure out how to do it that way. I want it to be like this: Code: <script> $(document).ready(function() { myFunction({ option1: 'value1', option2: 'value2', etc: 'etc' }); }); </script> But how do I recover this data so I can use it later? Hi all. I have a form that I am writing which needs to send information contained inside a textbox when the user presses the "Post Comment" button. I want it be sent as a parameter to the addComment() function. How can you do this??? I have been trying to figure it out for a while now but can't seem to get the syntax right. This is what my code looks like currently. If possible I would like this to work without referencing the name of this form. Code: <form method="post" name="form" action="" style="padding:0px; margin:0px;"> <textarea name="content" id="content" style="width:600px; height:114px; font-family:Verdana,Arial,Tahoma,Times New Roman; font-size:12px; border:1px #666 solid;" onFocus="this.value=''; this.onfocus=null;">Enter your comment...</textarea><br /> <input type="submit" value="Post Comment" id="v" name="submit" onclick="addComment(this.content.value);" /> <span id="wait"></span><span id="flash"></span> </form> Is it possible to use JavaScript to send a HTML FORM this way? (By the way, this is a huge guess - I don't know JavaScript very well) Code: <SCRIPT type="text/javascript"> function Cart1Function() { get.INPUT.quantity.value send.to.formsubmit1.php } function Cart2Function() { get.INPUT.quantity.value send.to.formsubmit2.php } </SCRIPT> <FORM action="?" method="post" name="form"> <DIV> <INPUT type="text" name="quanitity"> <INPUT type="submit" value="CART 1" onClick="Cart1Function"> <INPUT type="submit" value="CART 2" onClick="Cart2Function"> <DIV> </FORM> I want to make two forms sharing the same input (quantity). Hi there, I guess my question is very novice but I have to ask it. I can find lots of "form applications" on internet. But anytime I check them I cannot see any "send" button help. I mean I know that when I click it, it wont send the informations to my e-mail page. Because they don't show where to insert my email address there, in the example. So how can we make a form work for us, how can we arrange it to send the informations to our e-mail address? Do we need to use a php file for it? if yes, how? Regards and Thanks in advance Hi How do I send an array created in jQuery or Javascript to PHP? (page will be redirected to PHP) I'm thinking of URL parameters right now, but wont that result to a long URL? Is there another optimized way of sending the array? Here's my script. Which doesn't work. Here's my script, this works fine... send_array_to_other_page.html Code: $(function(){ //DECLARE ARRAY var arr = new Array(); var i = 0; $('#form').submit(function(e){ e.preventDefault(); var value = $('#box').val(); var index = arr.length; var list = ''; //ADD VALUE TO ARRAY arr[index] = value; //OUTPUT VALUES IN ARRAY for (var index in arr){ list+=index+': '+arr[index]+'<br/>'; $('#arrLength').html(arr.length); } //DISPLAY ARRAY $('#display').html(list); $('#form').get(0).reset(); //RESET FORM }); $('#send').click(function(){ window.location = 'send_array_to_other_page_2.php?list='+arr; }); }); This doesn't. It outputs Array content lost. Id also like to point out the the url of this page is send_array_to_other_page_2.php. Its missing the ?list= PHP Code: <?php $arr = $_GET['list']; echo 'The contents of the array are still... <br/>'; if(isset($arr)){ print_r($arr); } else { echo 'Array content lost'; } ?> Hi, I am facing a problem in passing replace() function as an argument in user defined java function, can any one help me how to resolve it? intention is to pass a file path to my user defined function, but before passing the path i want to replace the character '\' to '\\' I am posting my javascript function he <a href="#" onclick="OpenDocPreview('<%# Eval("PATH")%>'.replace(/\\/g,"\\\\"), '<%# Eval("Filename")%>')"><%# Eval("DocTitle") %></a> function OpenDocPreview(url, docname) { alert('message from search base : ' + url + ' ' + docname); } thank you, Hi, I wanted to know if there is way in Javascript to send a hidden variable to an external URL without actually submitting to the URL? Code below is what I intend to do. I want to use an image to do an onClick event and send the name to an external URL without actually doing a submit. Code: <td width="25"> </td> <input type="image" src="images/btn_Activate.gif" onClick="window.location.href='www.abc.com'"> <input type="hidden" name="name" value="<% = name %>"> </td> Thanks. Jeeten. (I also posted this on stackoverflow, but haven't had any replies.) I have a script that sends a POST to a php file, and gets a new integer (primary key). Then the script creates 3 new divs, with that ID included in them as an attribute. Now, I need to be able to grab the ID and give it back to PHP when the user updates it. (It's currently a div, but later it will be an editable form.) I was going to do this by creating a button in the same script that I use to create the divs, bearing the same integer and calling a function. The problem with this concept, is that I have no idea how to create a Unique variable to pass along to the function, so it knows which number to look at. Obviously, if I have only one variable that gets overwritten with each new entry - after all of the rows load, only the last row will have a variable that matches its id. Another option is to find the value of all attributes that bear the name data-integer-question and pass its number/integer to a function, when the user does something like keyup enter. However, I have no idea how to do that. obj.returnIntJson holds the integer that I've been talking about, which changes for each row. rowNumberObj.qarowcontainer is just a reference for the parent div, which doesn't get edited by the user - you can ignore it. The script gives a result like this: <div id="questioncolumn" class="questionColumnCSS" data-integer-question="701"></div> Suggestions on how to proceed? Here's the code for one of the divs, Thanks. PHP Code: qaRowQuestion = document.createElement('div'); qaRowQuestion.setAttribute('id', "questioncolumn"); qaRowQuestion.setAttribute('data-integer-question', obj.returnIntJson); qaRowQuestion.setAttribute('class',"questionColumnCSS"); qaRowQuestionParent = document.getElementById(rowNumberObj.qarowcontainer); qaRowQuestionParent.appendChild(qaRowQuestion); How can I call a PHP Function inside a Javascript Function? This is what I have so far, but I don't think I'm doing it the right way. Any suggestions? PHP Code: <?php function phpQuery(){ $query = mysql_query("INSERT INTO mytable VALUES('','name','email')"); } ?> <script type="text/javascript"> function delayQueries() { timeoutID = window.setTimeout(doQueries, 2000); } function doQueries() { var runQuery = "<?php phpQuery(); ?>"; } </script> I made a mouseover event of a caption on a picture, when I hover the opacity of the background color of the hover and the text goes down. What I want is that when I hover over the image which the caption is floating on, the onmouseover event gets activite. For an imaginary example: Code: function unhighlight(x) { x.style.backgroundColor="transparent" } Function ActivationFuction() { activate.function="unhighlight" } thanks Hi everyone, I am pretty new at javascript OOP. I have a javascript file that has plenty of javascript functions, variables, arrays, etc. I need to convert this into an object. Here is an example: Code: var myvar1 = ''; var myvar2 = new array(); var myvar3 = new array(); var myvar4; var myvar5 = 60; var myvar6 = ''; function myfunc1(){ myvar1 = 'hello'; return myvar1; } function myfunc2(somenum=0){ myvar5 = somenum; //calling myfunc1() from within this function. //do something in here } function myfunc3(){ //calling myfunc1() from within this function. for(i=0;i<somelength;i++){ myvar2 = myvar3[i]; (something to put into the array) } } 1. I need to create an object and put ALL the varibles (myvar1 - myvar5) in that object. 2. Then the first two functions "myfunc1 and myfunc2" inside the same object. 2. And the function myfunc3 needs to sit OUTSIDE my object as a regular javascript function. It calls on myfunc1 (which is inside the object) and also inserts data into myvar2 (which is classified inside the object) and myvar3 (which is classified inside the object as well). This is what i came up with, but it's not going well: Code: var myobj1 = function(){ this.myvar1 = ''; this.myvar2 = new array(); this.myvar3 = new array(); this.myvar4; this.myvar5 = 60; this.myvar6 = ''; var myfunc1 = function(){ this.myvar1 = 'hello'; return this.myvar1; } var myfunc2 = function(somenum=0;){ this.myvar5 = somenum; //calling this.myfunc1() from within this function. //do something in here } } function myfunc3(){ //calling mynewobj.myfunc1() from within this function. for(i=0;i<somelength;i++){ mynewobj.myvar2 = mynewobj.myvar3[i]; (something to put into the array) } } var mynewobj = myobj1; HELP.....!!!! i really want to get into object oriented world, so thanks in advance. If I use function or Function to create a javascript function, does it make any difference ? Whats the difference between two and in which situation shall I use either ? Likewise whats the difference between event and Event objects of JavaScript ? Thanks Please I have been having sleepless nights for days and could not resolve why this codes will not work. I will appreciate any assistance to resolve the coding reerroll the main problem is the function calculate (), does work when called. Please help <HTML> <HEAD> <TITLE>Feedback</TITLE> <SCRIPT TYPE="TEXT/JAVASCRIPT"> rate = new Array(4) rate[0] = 8 rate[1] = 4 rate[2] = 6 rate[3] = 12 function calculate() { howmuch = eval("document.form1.InsVal.Value") for(loop = 0; loop < document.form1.cover.length;loop++) if (document.form1.cover[loop].checked) level = loop + 1 where =document.form1.region.selectedIndex cost = eval(10 + howmuch /100*rate[where]*level) document.form1.guote.value =cost } function confirmPurchase() { if (confirm("Area you sure you wish to purchase insurance from us?")) document.form1.submit() } </SCRIPT> </HEAD> <BODY> <H1 ALIGN = CENTER>HotWheels</H1> <H2 ALIGN = CENTER>Skateboard Insurance Specialists</H2> <FORM NAME = form1 METHOD = post ACTION = "mailto:ioduwa@yahoo.com"> <P><B> Value of board:</B> <INPUT TYPE = text NAME = InsVal SIZE = 10> <P> Region <SELECT NAME= region> <OPTION = london> London <OPTION = southwest> South West <OPTION = rest>Rest of England <OPTION = wales>Wales </SELECT> <BR><INPUT TYPE = Radio NAME = cover> Third Party <BR><INPUT TYPE = Radio NAME = cover> Third Party Fire and Theft <BR><INPUT TYPE = Radio NAME = cover CHECKED> Comprehensive <P><INPUT TYPE = "button" NAME = "calc" VALUE = "Get guote" onClick ="calculate()"> <P><B> Your Quotation:<B> <INPUT TYPE = "text" NAME = "quote" SIZE = 10> <P><INPUT TYPE = "button" NAME = "done" VALUE = "Purchase" onClick = "comfirmPurchase()"> </FORM> </BODY> </HTML> Hi, I have a javascript code in my site which is similar to this: var menu1=new Array() menu1[0]='<hr style="color: \'#FFCC66\'; height: \'1\'; text-align: \'left\'; width: \'96%\'"><strong><font size=+2>text1</font></strong>' var menu2=new Array() menu2[0]='<hr style="color: \'#FFCC66\'; height: \'1\'; text-align: \'left\'; width: \'96%\'"><strong><font size=+2>text2</font></strong>' The list goes on for hunders of records. What I need to do, is to use a function in which I will pass the text1, text2, text3 as variables, and have the html code returned, since it's always the same. For example, I would need something like: var menu1=new Array() menu1[0]='display_html(text1)' var menu2=new Array() menu1[0]='display_html(text2)' This would save me a lot of bytes in the output file, but I'm not very familiar with javascript so I didn't manage to make it work. I tried using the document.write command in a function, but that forced the text to be displayed on my page, even though it was supposed to be shown only when the user clicks on a link. I'm using the "AnyLink Drop Down Menu" script from www.dynamicdrive.com. Any help would be highly appreciated! Hello, I have a php function PHP Code: function npclocs() { $npcl=$db->query("SELECT * FROM npclocation WHERE npclong < {$ir['userlongitute']}+5 AND npclong > {$ir['userlongitute']}-5 AND npclat > {$ir['userlatitude']}-5 AND npclat < {$ir['userlatitude']}+5 "); /*$npcarray = mysql_fetch_array($npcl);*/ $rows =0; while($row = $db->fetch_row($npcl)) { $nloc[]=$row; } foreach($nloc as $n) { echo "newpoints[" . $rows . "] = new Array(".$n['npclong'].", ".$n['npclat'].", ".$n['npciicon'].", ".$n['npclname'].", ".$n['npclname']."); "; $rows++; } } and I have a javascript function that I would like the results of this function to insert its results in the javascript here is the function in javascript Code: function addPoints() { //newpoints[0] = new Array(-73, 46, icon0, 'monroe', 'monroepopup'); //newpoints[1] = new Array(-69, 52, icon0, 'jackson', 'jacksonpopup'); //newpoints[2] = new Array(-45, 39, icon0, 'Benton', 'bentonpopup'); for(var i = 0; i < newpoints.length; i++) { var point = new GPoint(newpoints[i][1],newpoints[i][0]); var popuphtml = newpoints[i][4] ; var marker = createMarker(point,newpoints[i][2],popuphtml); map.addOverlay(marker); } } The commented out //newpoints is the old js array. my php function queries mysql and uses whiles and foreach to create the same output, as the old js array. I would like that php function result to insert its result into the js function. Is this possible? Thank you in advance. Hi I have a JavaScript function that has leaves floating around the screen and I need a way to have a checkbox turn on and off the function. Or I need a way to have a button turn off the script. I have the code to start the function on-loading the site. Any ideas are greatly appreciated. I got the falling leaves script from http://javascript.about.com/gi/o.htm...tip62.htm%3Ffm Hello. If the function called Change has ever been called, the function in window onload is to not be executed. This is what I have so far, but I am sure it's wrong or missing something. I tried to confirm the results with document.write or alert but am having trouble doing so. Code: window.onload=function(){ if (calledAtLeastOnce == false) { Change('big', 'http://www.adomainname.com/image.jpg'); } } function Change(id,src,w,h){ var calledAtLeastOnce = true; } Hi all. I have this simple javascript that initiates a flash player. Code: <script type="text/javascript"> function add_content(filedesc,filepath,whatarget) { var output = "" + filedesc + "</b><br />"; output += "<object type='application/x-shockwave-flash' data='mp3player.swf'>"; output += "<param name='movie' value='mp3player.swf'>"; output += "<param name='wmode' value='transparent'>"; output += "<param name='FlashVars' value='mp3=" + filepath + ">"; output += "</object></div>"; output += "" + whatarget + ""; document.getElementById("" + whatarget + "").innerHTML = output; } </script> and this takes care of the onclick event: Code: <a href="javascript:void;" onclick="javascript:add_content('Hello1','../m_music/omd.mp3','target1');">Omd</a><div id='target1'></div> <a href="javascript:void;" onclick="javascript:add_content('Hello2','../m_music/blondie.mp3','target2');">blondie</a> <div id='target2'></div> page and vars are going to be dynamic. My question is: if I press 'target1' it plays. When I press 'target2' second player plays in its div layer. How can I start one player while stopping another (I am guessing 'target1' must be hidden). I am going to have many mp3 files and I want each player to be in its rightful place. I've looked for functions, but I am not that experienced with JV syntax. Thank you. hi i have a sliding vertical menu in my page in the left side and in the right side i have a text say for eg: Home. So when i click on home, i need the left side vertical menu to slide and open and the home in the left side should get highlighted. How do i do this in javascript ???? Pls help!!!! |