JavaScript - Write Variable Text In New Window
Hi there,
i have one script which is supposed to pop up a new win and after it does write a piece of text in it. This text comes from inside the HTML area: Code: (script) function popupwin(whichOne) { var width = 450; var height = 490; var left = parseInt((screen.availWidth/2) - (width/2)); var top = parseInt((screen.availHeight/2) - (height/2)); var windowFeatures = "width=" + width + ",height=" + height + ",status=no,resizable=no,location=no,titlebar=no,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top; newwin = window.open("spSelect.html","spSelect",windowFeatures); spSelect.document.whichOne.value = whichOne; } (calling part in html) <a href="javascript: popupwin(Souvlaki);"><img src="images/orderbutton.gif" width="100" height="20" border="0"></a> (new win place where text is supposed to appear) <input name="whichOne" readonly="readonly" type="text" class="textfield"> Similar TutorialsHey there everybody! I'm learning javascript, and I am having trouble figuring out how to do this. Maybe you guys can help me out. What I need is for my main page to have a text field. Above the text field there should be a set of images for bold, italics, underline, etc; when you click on them it inserts the html code <b></b> at the cursor point. Next I want there to be a link, that when clicked will open a popup box with smileys. When you click on one of the smiley images it should insert the smiley code (example :smile: ) into the parent window text field. And would it be possible to make that work with pages of emotes? Or perhaps a second popup window? I hope I explained that without it sounding confusing. I would really appreciate any help. Here is my basic code, it does not include a popup code however. Code: <html> <script type="text/javascript"> function insert(el,ins) { window.lstText={}; if (el.setSelectionRange){ el.value = el.value.substring(0,el.selectionStart) + ins + el.value.substring(el.selectionStart,el.selectionEnd) + el.value.substring(el.selectionEnd,el.value.length); } else if (document.selection && document.selection.createRange) { el.focus(); var range = document.selection.createRange(); range.text = ins + range.text; } } </script> <body> <form> <textarea rows="20" cols="100" name="txt1" onfocus="window.lstText=this;"> This is sample text, click anywhere in here then choose on of the buttons above to see text inserted. </textarea><br /><br /> <img src="http://i570.photobucket.com/albums/ss141/vwcorrado/Docs_smiley.jpg" onclick="insert(window.lstText,'hello')"> <input type="button" value="hi" onclick="insert(window.lstText,'hi')"> <br /> </form> </body> </html> I have am writing a quiz to test one's knowledge. I am keeping track of the score using javascript function and when you click button, I have another JavaScript function calculate the result. I want to be able to print the result. But when I use document.write statement, the result is printed on another window and not at the end of the current window. I even tried positining the text using absolute in css style. document.write('<div id="header">'); document.write(res); document.write('</div>'); The above code is inside the function that evaluate the result. Any help would be useful. Thanks. Hi, Hope you can help me resolving this problem. I have an php script with this code: Code: print "document.write(\"<a href='{$items[$i][1]}' rel="nofollow" target='{$target}' class='{$cssprefix}item'>"; I want to change {$items[$i][1]} with: Code: javascript:window.open('{$items[$i][1]}', this.target, 'dialog,modal,scrollbars=no,resizable=no,width=500,height=900,left=-500,top=100'); How can i do that? Best Regards Mozack Is there anyway in JS to capture the user's IP address and then write it to the variable, ip_addy?
Hi all can someone guide me (total JS newbie) on this presumably pretty easy task? I have a "parent" page with some text inputs in it (a form). This is what I am after: -when the user clicks a link it pops open a new window via JS - "child" (this is working). -in the "child" window there are also some text inputs (another form) (done). -when the user changes the value for 'testChild_textInput_4' in the child window, then I want it to automatically set this same value, to effectively overwrite, what is currently in 'testParent_textInput_2' in the parent window. Presumably this involves an onChange event, but it is also OK with me if the needful (the text input's value in the parent window being overwritten) happens upon the child window's form submit. If anyone can show me either trick, I would be thrilled! I set up a test page to make this all easy to talk about: http://www.yellow-turtle.com/testDumpMe_parent.html Please let me know! Thanks! -John Is there any possibility to write a text file using Chrome/FF? On the other words, writing a text file w/o using ActiveX. Thank you.
Is there a javascript code so that you can disable a textarea but parts of the page can still add to the textarea if your peter i mean about the other javascripts you told me. Sorry if this is confusing just ask me and i will rewrite it
I need javascript to read height of an static multiline text and write height value into the var value? Is it possible? Hi, I have an idea for putting news articles on my phone to read later when I have time. I'd like to be able to right-click the text of an article and choose "Send to Phone Queue." When I've got a few articles in the queue, I'd like to be able to bluetooth the file to my phone. I know some HMTL and CSS, but I'm very much a novice when it comes to JavaScript. I'm thinking that I probably can't even do a lot of this with JS because of it's limitations (i.e. writing to a file). Will I need to use PHP or Java for writing/bluetoothing the file? I was playing around with extracting the body-text of an article from FoxNews.com. I didn't get very far but you can see where I'm going with it. I welcome any comments, criticisms, etc. Thanks for anything you say, even shooting this down as unrealistic. Code: function getBodyText() { var divList = document.getElementsByTagName('div'); for ( i=0; i<=divList.length; i++) { if (divList[i].getAttribute("class") == "entry-content KonaBody") { . . . I heard there is something called XMLHttpRequest that is compatible to all browsers. What does that actually do? Is there something to do with Javascript? Thank you.
Hi, I was hoping you could help me, I was wanting to write text to the screen but without re-writing the whole screen (e.g. document.write();. I wish to take text and put it in a function, modify it, then display it. So far I have: Code: <script type = "text/javascript"> function calculate(text){ var x = "10.0"; var gpa = text.replace(/0.0/g,x); document.getElementById("text").innerText=gpa; } </script> <p id = text >Your Grade Point Average (GPA) is: 0.0</p> <button type="button" onclick="calculate(text)">Calculate</button> Your help would be really appreciated I would like to know how to do things. 1. I would like to know how i would code a javascript so if i edit the text inside of either a certain div or in the javascript document itself (which ever would work, would like to have it take the text from a div but not too picky) and then have it write that text in other parts of the same page and other pages by like putting a javascript code in it's place or however you would do it. Basically if i write "hello world" in the div/javascript document, it will write "hell world" in multiple places just from me editing that one part. ok so help with this would be awsome. My second thing. 2. I would like to take and use some javascript function, such as document.write or what ever to do pretty much the same thing as my first thing as my first problem, but with a div, for like a navigation bar or etc. So any help would be greatly appreciated! =) THANKS! Hello: I have two input boxes on a form which receive the first and last name of a user. I want to be able to use charAt() to get the first letter in each box and pass it to a third box on the same form. Is this doable? May I request some help? I was thinking something like the function below would be the starting point --I stand correct, as it is not working. Code: <script type=\"text/javascript\"> var str=\"Mossa\"; <!--document.write(str.charAt(0));--> document.write('<INPUT TYPE=text size=2 VALUE=\"str.charAt(0);\">'); var str=\"Barandao\"; document.write('<INPUT TYPE=text VALUE=\"str.charAt(0)\">'); <!--document.write(str.charAt(0));--> </script> Any thoughts! Mossa I having trouble with this code, I have this timer running in a js file if the timer runs out then an alert box pops up letting the user know that they have been logged out. There is also a pop-up window and if the user press down on the key board then the timer resets. I have already done this in my test files, What I am trying to do is apply it to this other code and its a bit tricky. Below you will find my test code. test1.php PHP Code: <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript" language="javascript"> var test2 function popup() { test2=window.open( "test2.php", "myWindow", "status = 1, height = 300, width = 300, resizable = 0" ) } </script> </head> <body> <?php echo '<a href="#" onclick="popup()" >Click Here</a>'; echo '<embed src="logout_operator.wav" autostart="false" id="logout" width="0" height="1" loop="false">'; echo '<script type="text/javascript" language="javascript" src="test.js"></script>'; echo '<script type="text/javascript" language="javascript"> function timeout(logoutSound) { var soundLogout=document.getElementById(logoutSound); soundLogout.Play(); alert("Your session is expired please login again"); location = "http://www.google.com"; } </script>'; ?> </body> </html> test2.php (pop-up window) PHP Code: <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript" language="javascript" src="test.js"></script> </head> <body> <script type="text/javascript" language="javascript"> window.onkeydown = handle; function handle() { resetTimer(); return true; } </script> </body> </html> test.js Code: var timer = setTimeout("timeout('logout')", 5000); function resetTimer(d) { clearTimeout(timer); if (d!="done"){ if (location.href.indexOf("test2.php")!=-1){ window.opener.window.resetTimer("done"); } else{ test2.window.resetTimer("done"); } } timer = setTimeout("timeout('logout')", 5000); } What I am trying to do is apply the function and the button to this code: Code: var _h = { mi: function (link, title, ni, qi, width, height, ri) { return '<a href="' + link + '"' + (ri != null ? ' class="' + ri + '"' : '') + ' target="_blank" title="' + title + '" onclick="this.newWindow = window.open(\'' + link + '\', \'' + ni + '\', \'toolbar=0,scrollbars=0,location=0,status=1,menubar=0,width=' + width + ',height=' + height + ',resizable=1\');this.newWindow.focus();this.newWindow.opener=window;return false;">' + qi + '</a>'; } I have tried to put the test2 variable as _h but that didn't work at all. Any help would be much appreciated, thanks!!! I can't seem to figure out how to post a variable to a javascript pop-up window. I'm trying to get a the users input to post directly to the URL. For example: Code: <!--Pop-up--> <script type="text/javascript"> <!-- function expo() { window.open( "export.php?&export=<?PHP $myvar = $_POST['exportthis']; echo $myvar; ?>", "myWindow", "status = 1, height = 300, width = 300, resizable = 0" ) } //--> </script> <form action="" method="post"><input type=text value="pass-this-variable" name="exportthis"> <input type=button value="Export" name="Exp" onClick="expo()"> </form> Any suggestions? Hello, I use a iplocator api, which is javascript and gives out the city name, country and zipcode output PHP Code: <script language="JavaScript" src="http://www.somesite.com/somefile.js?key=apikey"></script> <script language="JavaScript"> <!-- document.write(ip2location_isp() + ', ' + ip2location_city() + ', ' + ip2location_zip_code() + ', ' + ip2location_net_speed()); //--> </script> my question or where i need help is that, i would like to output each of those as a hidden text field, so later i can store into mysq database with POST method from the hidden field. thank you in advance for your time n help Hello folks, I have a very simple problem...but stuggling with this. I have a popup window (.aspx page). It will called from a parent .aspx page. All I want to do is read the name of the parent aspx page in popup page. Based on the name of the parent window, in the page_load event of the popup window, I want to execute some code. But the only catch is that, I am not able to read the parent window name until the page_load event (of popup window) complets the execution. 1. calling popup window from parent window. Code: Code: function OpenWindow_HistoricalRuns() { var windowIncsimHistRuns = window.open('MVal.aspx', 'Market', 'width=350,height=425,scrollbars=0'); windowIncsimHistRuns.moveTo(500, 300); } In the body of the popup window the following function tries to read the parent window name: Code: function SetDisplay() { document.getElementById('<%=TextBoxSourcePageName.ClientID%>').value = window.parent.name; } In the page_load event of the popup window, I want to see what is value of TextBoxSourcePageName control. I hoped I will get 'MarketVal'. But I never get anything. Code: protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { try { if (TextBoxSourcePageName.Text == "MarketVal") } } } In my situation, I need to know the window.parent.name by the time Page_load event gets triggered on the popup window. Because I have to do some specific thing in the Page_Load event (of popup window), based on window.parent.name. So my fundamental question is, which one will get fired first in an .aspx page. 1. Javascript in the body tag or 2. Page_load event of the .aspx page. If Javascript function in the body tag gets fired first, then by the time I get to Page_Load event, I should already have whatever I need. thanks Hey, I'm looking for a way to get a variable from a parent window in a child window. I'm aware that you can write the variable to a hidden field and then get the field's value in the child window, but I'm looking for a cleaner (all JS preferable) way of doing this. Something like this, but I believe this is an out-dated solution: Code: var str = window.opener.str; alert(str); Any solutions? Sorry, this is a newbie question, and probably really dumb, but... If I create a function that looks like this... Code: function recall(tim) { setTimeout("window.location.replace('somepage.html')",tim); } ...it works fine when called. However; I want to be able to pass the page url in a variable, something like this... Code: function recall(tim, myurl) { setTimeout("window.location.replace(myurl)",tim); } ...but this creates an error, saying "myurl is not defined." Even if I simplify the code and place the url in a variable within the function... Code: function recall(tim) { var myurl="somepage.html"; setTimeout("window.location.replace(myurl)",tim); } ...I still get the "myurl is not defined" error, even tho I am defining it. Plz can someone explain what I'm doing wrong. Tkx... --paul |