Printable Version of Topic

Click here to view this topic in its original format

HTMLHelp Forums _ Client-side Scripting _ Document.write help

Posted by: dani_boy Apr 24 2009, 12:47 PM

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

Posted by: pandy Apr 24 2009, 01:09 PM

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\!');

Posted by: asmith Apr 28 2009, 07:07 AM

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?

Posted by: Darin McGrew Apr 28 2009, 12:44 PM

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.

Posted by: asmith Apr 28 2009, 01:43 PM

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.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)