JavaScript - Return A Value In Javascript Help Needed
i have this line of code:
Code: <a href="#" id="profilelink" name="link2" onClick="viewornot(<?php echo $freechat_id ?>)"><?php echo $freechat_list; ?></a> //call the JS onclick and if OK was click do the message box and send button here then i have my JS: Code: function viewornot(id) { var e = confirm('Do you want to view this profile?'); if (e == true) { window.location.href = "http://www-rainbowcode-net/apps_dev.php/profiles/showprofilepersonal?id="+id; window.location('http://www-rainbowcode-net/apps_dev.php/profiles/showprofilepersonal?id='+id); return true; } else { var e2 = confirm('Do you want to send a message?'); if (e2 == true) { //if ok was clicked send value back?? return e2; } } } on the e2 confirm: if i clicked OK how can i send a value back(so that i know OK was clicked) so that i can then produce the message box and send button and do the rest of the code to send a message??? thank you Similar Tutorialshi, i wanna get the value from javascript to php variable. here is my code, <html> <body> <select name="drop" size="10" onchange="drp_selectd_value(this)"> <option>One</option> <option>Two</option> <option>Three</option> <option>Four</option> <option>Five</option> </select> <?php echo "The PHP value".'<script>value_return();</script>'; $p='<script>y;</script>'; ?> </body> </html? <script> var x; var y=100; function drp_selectd_value(sdf) { x=sdf.value; alert("Value is : " +x); value_return(x); } function value_return(val) { alert("Second Function calling : "+val ); return val; } </script> This code does not working!!! How can i fix tis problem???I m expecting for the reply.. Thanks in advance Hello, I made a little code for my website but it doesn't work and I can't find out what the problem is. The problem is that the line return 2; does return undefined and not 2 as expected. I also tried to replace var xmlhttp2 = ''; for var xmlhttp2 = null; but it still not work. Does anyone know what is incorrect? Thanks in advance, PHP Code: function get_image(url) { var xmlhttp2 = ''; xmlhttp2=GetXmlHttpObject() xmlhttp2.onreadystatechange=function() { if (xmlhttp2.readyState == 4) { return 2; } }; xmlhttp2.open("GET", 'image_print.php?url=' + url, true); xmlhttp2.send(null); //return output; } Its a ads rotation code: Don know why it doesnt work... Code: <body> <div align="center"> <script> var brw=navigator.appName; var id; if(brw == "Netscape") id=1; if(brw =="Microsoft Internet Explorer") id=2; if(brw == "Opera") id=3; var delay=10000; var k=0; var fcontent=new Array(); var b=new Array(); function go(k) { b[0]='' b[1]='<iframe src="http://........." width="460" height="60" scrolling="no" name="cpm" frameborder="0"></iframe>' b[2]='<iframe width="468" height="60" allowtransparency="false" frameborder="0" hspace="0" vspace="0" marginheight="0" marginwidth="0" scrolling="no" src="http://............"></iframe>' b[3]='<iframe width="468" height="120" allowtransparency="false" frameborder="0" hspace="0" vspace="0" marginheight="0" marginwidth="0" scrolling="no" src="http://............"></iframe>' if(id != 3) b[4]='<iframe width="1" height="1" allowtransparency="false" frameborder="0" hspace="0" vspace="0" marginheight="0" marginwidth="0" scrolling="no" src="http://......."></iframe>' else b[4]='' b[5]='..' ..... ..... b[36]='.... ' return; } begintag='<div style="font: normal 14px Arial; padding: 5px;">'; //set opening tag, such as font declarations fcontent[0]=b[0]+b[1]+b[2]+b[3]+b[4]+b[5]; fcontent[1]=b[6]+b[7]+b[8]+b[9]+b[10]; fcontent[2]=b[11]+b[12]+b[13]+b[14]+b[15]; fcontent[3]=b[16]+b[17]+b[18]+b[19]+b[20]; fcontent[4]=b[21]+b[22]+b[23]+b[24]+b[25]; fcontent[5]=b[26]+b[27]+b[28]+b[29]+b[30]; fcontent[6]=b[31]+b[32]+b[33]+b[34]+b[35]; fcontent[7]=b[0]+b[36]; closetag='</div>'; var ie4=document.all&&!document.getElementById; var DOM2=document.getElementById; var index=0; //function to change content function changecontent(){ if (index>=fcontent.length ) { index=0; ++k;delay=delay+5000; } go(k); if(delay>15000){return;} if (DOM2){ document.getElementById("fscroller").innerHTML=begintag+fcontent[index]+closetag } else if (ie4) { document.all.fscroller.innerHTML=begintag+fcontent[index]+closetag; } ++index; setTimeout("changecontent()", delay); } if (ie4||DOM2) document.write('<div id="fscroller" style="width:700px;"></div>'); if (window.addEventListener) window.addEventListener("load", changecontent, false) else if (window.attachEvent) window.attachEvent("onload", changecontent) else if (document.getElementById) window.onload=changecontent </script> </div> </body> here go(k); function might do this mass (output-->NaN). plz b a help... The website I'm updating is peachbasketonline.com. I am not the original web designer. I'm trying to reach an install page that is located in the directory, but anytime I go to a page outside of the site navigation (i.e. part of site navigation: About Us works fine, versus a page outside of site navigation: peachbasketonline.com/anythingelse) it automatically takes you back to the home page. Is there enough info here for someone to tell me if javascript is doing this? I just don't know what I'm looking for. Hi there, I am trying to build an interface to upload files and change some of the form (hidden) values depending on the file uploaded, here is where I got so far: Code: $('#buttonUpload').click(function (){ $.ajaxFileUpload({ url:'doajaxfileupload.php', secureuri:false, fileElementId:'fileToUpload', dataType: 'txt', success: function (data, status){ alert("File is uploaded,"); if(typeof(data.error) != 'undefined'){ if(data.error !=''){ alert(data.error); } else{ alert(data.msg); } } document.getElementById('buttonUpload').style.color="green"; document.getElementById('isfileuploaded').value="green"; }, error: function (data, status, e){ alert(e); } }); return false; }); My problem is that I want doajaxfileupload.php to return a variable to javascript/change some html form value. The code works as it is for the file upload, I just need to add something for the output, any suggestion? Edit: I just noticed that some previous part of the code is still the the part that changes the color of the button depending if the file is uploaded or not. Now I want those values to change depending on what file is uploaded. I tried to use the script to return the user to the previous page by clicking the link, and it did work, however, it would return me to the previous website I visited and not just the previous page within my site. Is there a way to override it by changing the code or is the code definitive? This was the code I had tried to use: Code: <a href="javascript:history.go(-1)">Back</a> Hi, I've a Javascript function where i'm sending an return value. How do i capture this return value from HTML. My javascript func is as below: Code: function check() { var frm=document.forms.stream_selection sel_num = new Array(); Parr = new Array(); for(j=1;j<1000;j++) { if(frm[j] != null) { if(!frm[j].checked) { frm[0].checked=false } else { Parr.push(j); ParrStr=Parr.join(','); alert(Parr); } } } return(ParrStr); } My HTML call function is as below: Code: echo "<td><center><input name=\"sstreamname\" type=\"checkbox\" onclick=\"check():return true;\"></center></td></tr></font></center></tr></font></center>"; How do i get the value of ParrStr and transfer this to next form. I'm using PHP . Thanks, Ramki. Ok, guys. I'm new to JavaScript, so go easy. I'll be asking bunches of "dumb" questions for a while. 1st question, and the only one for now ... Say I have the following function: Code: function SwapValues(SwapVal1,SwapVal2) { TempSwapVal=SwapVal1; SwapVal1=SwapVal2; SwapVal2=TempSwapVal; } I don't care about the return value of the function itself, but I do need the new values of SwapVal1 and SwapVal2. In ASP when I do this, the values get returned. How do I get this to work in JS? I don't understand the logic of Break, Return False, Return True. It was never really covered in our college class, and I see everyone using it. I got an A in the class, if that 'proves' that I really tried to apply myself. NOTE: I understand what the function is doing. I just don't understand WHEN to use break, return false or return true if the the translator can determine the conditional statements. PHP Code: function submitForm(){ var ageSelected = false; for (var i=0; i<5; ++1){ if (document.forms[0].ageGroup[i].checked == true) { ageSelected = true; break; } } if (ageSelected == false){ window.alert("You must select your age group"); return false; } else return false; } if the the translator can determine the conditional statements, why not write it like this: PHP Code: function submitForm(){ var ageSelected = false; for (var i=0; i<5; ++1){ if (document.forms[0].ageGroup[i].checked == true) { ageSelected = true; break; // what's the point for the 'break'? Won't the rest of the code be ignored since it passed the first condition? } } if (ageSelected == false){ window.alert("You must select your age group"); return false; } // why not leave the last else out? is it just a 'safety' catch, in case something other than true or false is inputted? else return false; // what's the point? } Questions: Why use return true, if the translator knows it's ture? Why use "return false" if the translator knows it's false and the alert window has already gone up? why not use "break" to stop the code? Why use the "return false" at the end "else" statement? Hi all, Please keep in mind: this is the first code I have ever written -- much of it with help from this forum and the skeleton from other corners of the JS community. Thanks! But now for the problem... I'm developing am income tax calculator, and everything is going swell. Currently the user can type in their adjusted gross income (AGI), hit submit, and learn the amount of income tax they would pay, their tax rate, and their income after tax. I've played around with the events to get the submit button to work in FF, IE, Chrome and Safari -- and I've gotten the enter button to work before with some stock code, but here's the catch: when the user presses enter, i want the focus to leave the input box. I don't care where it goes (submit button, I suppose?) but i need it to leave the input field so the onfocus="clearText(this);" event can fire when they return to type in a new income. Any ideas? Thanks in advance. Code: <script language="javascript" type="text/javascript"> function TotalGrossPerYear() { var Calc = document.NetIncome; if (Calc.InputRad[0].checked) { if ((Calc.AGI.value > 500000)) { Bracket3(); } if ((Calc.AGI.value > 200000 ) && (Calc.AGI.value <= 500000)) { Bracket1(); } if ((Calc.AGI.value <= 200000)) { Bracket2(); } } else if (Calc.InputRad[1].checked) { if ((Calc.AGI.value > 1000000)) { Bracket3(); } if ((Calc.AGI.value > 400000 ) && (Calc.AGI.value <= 1000000)) { Bracket1(); } if ((Calc.AGI.value <= 400000)) { Bracket2(); } } } function Bracket1() { var Calc = document.NetIncome; if (Calc.InputRad[0].checked) { Calc.TaxableIncome.value = (parseFloat(Calc.AGI.value) - 200000) ; Calc.AmtDue.value = Math.round((parseFloat(Calc.TaxableIncome.value) * 0.05)) ; Calc.AmtLeft.value = (parseFloat(Calc.AGI.value) - parseFloat(Calc.AmtDue.value)) ; Calc.TaxRate.value = (parseFloat(Calc.AmtDue.value) / parseFloat(Calc.AGI.value) * 100).toFixed(2) + " %"; } else { if (Calc.InputRad[1].checked) { Calc.TaxableIncome.value = (parseFloat(Calc.AGI.value) - 400000) ; Calc.AmtDue.value = Math.round((parseFloat(Calc.TaxableIncome.value) * .05)) ; Calc.AmtLeft.value = (parseFloat(Calc.AGI.value) - parseFloat(Calc.AmtDue.value)) ; Calc.TaxRate.value = (parseFloat(Calc.AmtDue.value) / parseFloat(Calc.AGI.value) * 100).toFixed(2) + " %"; } } } function Bracket2() { var Calc = document.NetIncome; if (Calc.InputRad[0].checked) { Calc.TaxableIncome.value = 0 ; Calc.AmtDue.value = Math.round((parseFloat(Calc.TaxableIncome.value) * 0.05)) ; Calc.AmtLeft.value = (parseFloat(Calc.AGI.value) - parseFloat(Calc.AmtDue.value)) ; Calc.TaxRate.value = (parseFloat(Calc.AmtDue.value) / parseFloat(Calc.AGI.value) * 100).toFixed(2) + " %"; } else { if (Calc.InputRad[1].checked) { Calc.TaxableIncome.value = 0 ; Calc.AmtDue.value = Math.round((parseFloat(Calc.TaxableIncome.value) * 0.05)) ; Calc.AmtLeft.value = (parseFloat(Calc.AGI.value) - parseFloat(Calc.AmtDue.value)) ; Calc.TaxRate.value = (parseFloat(Calc.AmtDue.value) / parseFloat(Calc.AGI.value) * 100).toFixed(2) + " %"; } } } function Bracket3() { var Calc = document.NetIncome; if (Calc.InputRad[0].checked) { Calc.TaxableIncome.value = (parseFloat(Calc.AGI.value) - 200000) ; Calc.AmtDue.value = Math.round((parseFloat(Calc.TaxableIncome.value) - 300000) * 0.09) + (300000 * 0.05) ; Calc.AmtLeft.value = (parseFloat(Calc.AGI.value) - parseFloat(Calc.AmtDue.value)) ; Calc.TaxRate.value = (parseFloat(Calc.AmtDue.value) / parseFloat(Calc.AGI.value) * 100).toFixed(2) + " %"; } else { if (Calc.InputRad[1].checked) { Calc.TaxableIncome.value = (parseFloat(Calc.AGI.value) - 400000) ; Calc.AmtDue.value = Math.round((parseFloat(Calc.TaxableIncome.value) - 600000) * .09) + (600000 * 0.05) ; Calc.AmtLeft.value = (parseFloat(Calc.AGI.value) - parseFloat(Calc.AmtDue.value)) ; Calc.TaxRate.value = (parseFloat(Calc.AmtDue.value) / parseFloat(Calc.AGI.value) * 100).toFixed(2) + " %"; } } } function Couple() { var Calc = document.NetIncome; Calc.AGI.value = ""; Calc.TaxableIncome.value = "--------"; Calc.AmtDue.value = "--------"; Calc.AmtLeft.value = "--------"; Calc.TaxRate.value = "--------"; } function Individual() { var Calc = document.NetIncome; Calc.AGI.value = ""; Calc.TaxableIncome.value = "--------"; Calc.AmtDue.value = "--------"; Calc.AmtLeft.value = "--------"; Calc.TaxRate.value = "--------"; } function clearText(thefield){ if (thefield.value==thefield.value) thefield.value = "" } </script> </head> and the html... Code: <body> <form name=NetIncome> <table border=5> <th align=left> <ol> <li>Select Individual or Joint filing status. <li>Enter your Adjusted Gross Income. <li>Submit to calculate. <li>Please reset after each calculation. </ol> </th> <tr> <td><font size=5><input type=radio name=InputRad value=PerHour onclick="Individual()"><u>Individual</u> <input type=radio name=InputRad value=PerYear onclick="Couple()"><u>Joint</u></font></td> </tr> <tr><td><input type=text name=AGI size=30 id="txtExamplethree" onfocus="clearText(this);" onsubmit="TotalGrossPerYear();" onblur="this.value=this.value.replace(/[^\d\.]/g, '');" value="Select filing status" maxlength="20" />Adjusted Gross Income </td></tr> <tr><td><input type=text name=TaxableIncome id="txtExampletwo" readonly="readonly" size=30 value="">Taxable Income</td></tr> <tr><td><input type=text name=AmtDue id="txtExampleone" size=30 readonly="readonly" value="">Amount Due in Taxes</font></td></tr> <tr><td><input type=text name=AmtLeft id="txtExample" size=30 readoanly="readonly" value="">Income after Tax</font></td></tr> <tr><td><input type=text name=TaxRate size=10 readonly="readonly">Tax Rate</td></tr> <tr><td align=center><input type="button" value="Submit" onfocus="TotalGrossPerYear(); formatNumber(); formatNumberone(); formatNumbertwo(); formatNumberthree();" /><input type=reset value="Reset Form"></td></tr> </table> </form> Hi room, Hey, I opened up the source code for this page in google chrome and since i'm learning javascript, i wanted see if i could "read" it and figure out what was going on. I'm am having the hardest time understanding "return false" and "return true". Could someone step me through this via interpreting this code (in bold typeface): Code: var DefaultValue = 'Search'; function clearSearch() { if (document.searchForm.q.value == DefaultValue) { document.searchForm.q.value = ''; } } function validateSearchHeader() { if ( document.searchForm.q.value == '' || document.searchForm.q.value.toLocaleLowerCase() == DefaultValue.toLocaleLowerCase() ) { alert('Please enter at least one keyword in the Search box.'); document.searchForm.q.focus(); return false; } return true; } Thanks! I'm working very hard to create a dynamic web-site for use in the education sector using server-side php/MySQL and client-side HTML with javascript. I have a logon page (index.php) which looks to see if the cookie 'mylogon' is set with the value 'Again'. This cookie is set when the PHP element on the server detects an invalid username/password combination. If so I have a javascript function (see below) call from the HTML <body onload="check_invalid_user()"> I know that the function Get_Cookie is working ok and that the javascript variable 'again' has the value 'Again' in it and has a length of 5. The alert function is not executed though. function check_invalid_user() { again = Get_Cookie('mylogon'); // document.write(again); // document.write(again.length); If (again == 'Again') { alert("User-id and/or password incorrect -- Please re-enter"); } } ============= Any help would be appreciated Many thanks in advance. (Yeah you guessed it I'm new and raw to this stuff. new to JavaScript, simple question... question: how do i determine an output from a prompt to be bold? e.g. a user enters "hello" and the output printed from the prompt becomes bold one=parseFloat(prompt('enter number',0.bold)); I have a script that works good, but it says undefined underneath, this must mean an error. But I cant work out how to get rid of it. This is the html it is a transistional XHTML doc type. Code: <div id="slidedom"> <script type="text/javascript" src="js-files/slider.js"></div></script> Then I have the js file which I will have to post all of as I am not sure of the error bit. Code: var variableslide=new Array() //variableslide[x]=["path to image", "OPTIONAL link for image", "OPTIONAL text description (supports HTML tags)"] variableslide[0]=['images/sign-1.gif'] variableslide[1]=['images/sign-3.gif'] variableslide[2]=['images/sign-4.gif'] //configure the below 3 variables to set the dimension/background color of the slideshow var slidewidth='188px' //set to width of LARGEST image in your slideshow var slideheight='60px' //set to height of LARGEST iamge in your slideshow, plus any text description var slidebgcolor='#FFF' //configure the below variable to determine the delay between image rotations (in miliseconds) var slidedelay=3000 ////Do not edit pass this line//////////////// var ie=document.all var dom=document.getElementById for (i=0;i<variableslide.length;i++){ var cacheimage=new Image() cacheimage.src=variableslide[i][0] } var currentslide=0 function rotateimages(){ contentcontainer='<center>' if (variableslide[currentslide][1]!="") contentcontainer+='<a href="'+variableslide[currentslide][1]+'">' contentcontainer+='<img src="'+variableslide[currentslide][0]+'" border="0" vspace="3">' if (variableslide[currentslide][1]!="") contentcontainer+='</a>' contentcontainer+='</center>' if (variableslide[currentslide][2]!="") contentcontainer+=variableslide[currentslide][2] if (document.layers){ crossrotateobj.document.write(contentcontainer) crossrotateobj.document.close() } else if (ie||dom) crossrotateobj.innerHTML=contentcontainer if (currentslide==variableslide.length-1) currentslide=0 else currentslide++ setTimeout("rotateimages()",slidedelay) } if (ie||dom) document.write('<div id="slidedom" style="width:'+slidewidth+';height:'+slideheight+'; background-color:'+slidebgcolor+'"></div>') function start_slider(){ crossrotateobj=dom? document.getElementById("slidedom") : ie? document.all.slidedom : document.slidensmain.document.slidenssub if (document.layers) document.slidensmain.visibility="show" rotateimages() } if (ie||dom) start_slider() else if (document.layers) window.onload=start_slider I have taken out the credit, as I have changed it a bit, but will reinstate it later on. All I really need to know is how to define it in the XHTML maybe. Can anyone help? How to create a popup blocker with javascript? I am looking for solution to open Enquiry form [Ex: send-query.php] through javascript linking. How can I do that? And how to display a popup blocker message like in the attached file? This is the url of my pop up image: http://www.rhapsody.com/thompson-squ...mpson-square-2 [When you click on play button then if you have popup blocker enabled you will get popup blocker message from the site] Pretty pretty please help me with this I am running out of time and pulling my hair out with this whole thing. Thanks a million in advance! Rhonda <!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>Untitled Document</title> <script> function numberGuess() { stringVar=prompt("Enter your guess number"); while (stringVar<999) { } } </script> <script> function enterNames() { stringVar=prompt("Enter name"); } </script> <script> function enterProducts() { stringVar=prompt("Enter product name"); return } </script> </head> <body> <p> </p> <h1>WDV221 Intro Javascript</h1> <h3 align="center">Javascript Loops</h3> <p>Topics: loops, for loops, while loops, sentinels!</p> <p>Place all script code on this page.</p> <p>1. Create a function that will ask you for a number until you enter 999 which will end the loop. You do not need to display the number. </p> <p>2. Create a function that will ask you for a name until you tell the function that you do not have any more names. After you enter each name it will ask you if you have more names to enter. If you enter yes the process will continue. Display each name at the end of the following sentence.</p> <p>The name you entered is: </p> <p>3. Create a runtime script that will use a prompt( ) to accept how many products will be displayed. Use a for loop to display "Product Name" and the product number as a <p> element.</p> <p><strong>Example output:</strong></p> <p>Product Name 1</p> <p>Product Name 2</p> <p>...</p> <p>4. Create a runtime script that will use a nested for loop to create a table with 3 rows and 5 cells. Place the same number or a letter in each cell. </p> <p>Hint: Write a table in HTML. Do a row first then do multiple rows. </p> <p>5. Create a function called totalSales( ) that will ask the user to enter an amount until you enter "done". Add those amounts together and display them in an alert when the user is done entering amounts..</p> <p>Have fun!!</p> </body> </html> I am still learning javascript so forgive me if this question is a bad one, I am making scripts for Greasemonkey for a website I am a part of. One of the developers recently commented out (in the source code) a feature that was available before. It is a Football MMORPG game and it used to show college players 40 times but over the past month he commented out the tag that held the script function. I want to know if i can either A) write a js code that can remove the comment tag in the source code or B) write a code that will just add another tag under that and have that js function that was commented out valid. I tried something but ended up just having that function pasted onto the page instead of having it put into the source to have it read by the rest of the data.. here is what im talking about <TABLE width=800 cellspacing=0> <tr> <td colspan=3 style="FONT-SIZE: 11pt"> <b>Hometown:</b>Fort Hunt, VA<br> <b>Height:</b>6-0<br> <b>Weight:</b>206<br> <!--b>40 Time:</b><if rs("team_id")>0 or bRated then><=formatnumber(rs("forty"),2)><br><end if --> i just want to see if there was any way to just delete the comment out of it so i can get this feature again is all. Any help would be awesome... and sorry for the long post I tried to write the variable my_var into a text file but it only shows null after executing the code. Can anybody help pls?? Below is my code <html> <head> <script language="javascript"> var my_var function WriteToFile() { my_var = 123; document.write(<?php $file="file.txt"; $fh = fopen($file, 'w') or die("can't open file"); ?>; document.write(<?php $stringData = my_var ?>; document.write(<?php fwrite($fh, $stringData); ?>; document.write(<?php fclose($fh); ?>; } </script> </head> <body onLoad="WriteToFile();"> <p>Hello World</p> </body> </html> |