The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> Document.write help, Im going nuts
dani_boy
post Apr 24 2009, 12:47 PM
Post #1





Group: Members
Posts: 1
Joined: 24-April 09
Member No.: 8,427



Hey folks, im kinda stucked with this document.write thing..

I want to use document.write on this code:
CODE
<html>
<head>
<style type= "text/css">
<!--
INPUT {font-size:10px}
.input{height:17px;font-size:10px}
SELECT {font-size:10px}
.select{height:17px;width:17;font-size:10px}
BODY {margin-left:0; margin-right:0; margin-top:0; margin-bottom:0;
width:100%;height:100%;overflow:hidden;background-color:threedface;}
-->
</style>
<script type="text/javascript">
    function clearText(field){

    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;

}
</script>
<script type="text/javascript">
function dosearch() {
var sf=document.searchform;
var submitto = sf.sengines.options[sf.sengines.selectedIndex].value + escape(sf.searchterms.value);
window.location.href = submitto;
return false;
}
</script>
</head>
<body>
<form name="searchform" onSubmit="return dosearch();">
<select name="sengines">
<option value="http://sayip.info/lookup.php?ip=" selected>Location</option>
<option value="http://sayip.info/whoislookup.php?whois=">Whois</option>
</select>
<input name="searchterms" type="text" onFocus="clearText(this)" onBlur="clearText(this)" value="Insert Ip...">
<input type="submit" name="SearchSubmit" value="Go">
</form>
</body>
</html>


To be more specific i need something like this:
CODE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
function sayip(){
var newWindow = window.open("about:blank", "width=200, height=200, resizable=no, maximizable=no");
newWindow.document.write("<html>\n<head>\n<title>Sayip Tools</title>\n</head>");
newWindow.document.write("<body>\n");
newWindow.document.write("<form name="searchform" onSubmit="return dosearch();">\n");
newWindow.document.write("<select name="sengines">\n");
newWindow.document.write("<option value="http://sayip.info/lookup.php?ip=" selected>Location</option>\n");
newWindow.document.write("<option value="http://sayip.info/whoislookup.php?whois=">Whois</option>\n");
newWindow.document.write("</select>\n");
newWindow.document.write("<input name="searchterms" type="text" onFocus="clearText(this)" onBlur="clearText(this)" value="Insert Ip...">\n");
newWindow.document.write("<input type="submit" name="SearchSubmit" value="Go">\n");
newWindow.document.write("</form>\n");
newWindow.document.close();
self.name = "main";
}
//  End -->
</script>
</head>

<body>
<input type=button value="Search" onClick="sayip()">
</p>
</body>
</html>


I know its everything wrong, thats why i came across this site.lol

I aprecciate any help on this, thanks in advance
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies(1 - 4)
pandy
post Apr 24 2009, 01:09 PM
Post #2


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



To start with the first error my browser's debugger flags...

CODE
newWindow.document.write("<form name="searchform" onSubmit="return dosearch();">\n");


You can't nest quotes of the same kind like that. The browser will take the lefthand quote around "searchform" as the closing quote for the whole document write, like this: "<form name=" .

Either nest alternate double and single quotes, e.g. document.write('<form name="searchform"... '); or escape the quotes inside the string with a backslash, \"searchform\" . Personally I always escape quotes in strings, because I think it keeps it neat and I can use any quote type I like around the whole thing.

You should also escape any slashes in document written closing tags, e.g. <\/form>

"Escaping" a character tells the browser it should see it as a literal character and not as part of JavaScript syntax. As you have understood by now, backslash is what you use to escape characters in JS. smile.gif

This produces perfectly normal text.
CODE
document.write('\H\e\l\l\o\!');
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
asmith
post Apr 28 2009, 07:07 AM
Post #3


Advanced Member
****

Group: Members
Posts: 198
Joined: 26-December 07
Member No.: 4,586



Hope I'm not changing the subject since it is about document.write

should this function be placed where it is about to write?

forexample :

CODE
<table id="table">
<tr><td>content</td></tr>
</table>


How can I tell document.write to write '<tr><td>more content</td></tr>' AFTER the first row?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Darin McGrew
post Apr 28 2009, 12:44 PM
Post #4


WDG Member
********

Group: Root Admin
Posts: 8,365
Joined: 4-August 06
From: Mountain View, CA
Member No.: 3



As I understand it, there is no way to do that. You need to create the whole table with JavaScript, or you need to put the JavaScript inside a td element. Or you could use the DOM to add table rows, rather than using document.write.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
asmith
post Apr 28 2009, 01:43 PM
Post #5


Advanced Member
****

Group: Members
Posts: 198
Joined: 26-December 07
Member No.: 4,586



hmm, Something like this :

CODE

<table id="table">
<tr><td>content</td></tr>
<script>
function addMoreRow()
{
document.write('<tr><td>more content</td></tr>');
}
</script>
</table>

<div onclick="addMoreRow();">click me</div>


edit : I tried it myself. It removed the "content" row, and replaced "more content".
I guess I gotta try other ways.

This post has been edited by asmith: Apr 28 2009, 01:48 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th March 2024 - 05:12 AM