Follow us on Twitter!
Imagination is more valuable than knowledge - Albert Einstein
Thursday, April 24, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 26
Guests Online: 23
Members Online: 3

Registered Members: 82897
Newest Member: salim
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

JS Page generator help


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 21-01-09 01:16
New to Javascript programming so not quite sure what I did wrong on this one...

Code
<title>Staff Page Generator</title>
</head>

<script>
function go() {

first = document.info.first;
last = document.info.last;
info = document.info.info;

name = first + " " + last;

email = last + first.substring(0,1) + "@carthage.k12.mo.us";

page = "*!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"" + "<br /><br />" + "*head" + "<br /><br />" + "*title" + first + "*/title" + "<br /><br />" + "*meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"" + "<br /><br />" + "*link href="style.css" rel="stylesheet" type="text/css" /" + "<br /><br />" + "*/head" + "<br /><br />" + "*body" + "<br /><br />" + "*table" + "<br /><br />" + "*tr class="blue"" + "<br /><br />" + "*td colspan="4"*h1" + first + " " + last + "*/h1*/td" + "<br /><br />" + "*/tr" + "<br /><br />" + "*tr class="grey"" + "<br /><br />" + " *td width="160" rowspan="3" class="white"" + "<br /><br />" + " *img src="../Teacher Staff Photos/images/" + last + ".gif" alt="" + name + "#" width="150" height="188"" + "<br /><br />" + "*td width="480" colspan="3" class="white"" + "<br /><br />" + info + "<br /><br />" + "*/td" + "<br /><br />" + "*/tr" + "<br /><br />" + "*tr class="grey"" + "<br /><br />" + "*td colspan="3" class="white"*/td" + "<br /><br />" + "*/tr" + "<br /><br />" + " *tr class="grey"" + " *td colspan="3" class="white"*a href="mailto:" + email + "#"" + email + "*/a*/td" + "<br /><br />" + "*/table" + "<br /><br />" + "*p align="center"*img src="../images/BLUE-TIGER.gif" width="390" height="100"*/p" + "<br /><br />" + "*/body" + "<br /><br />" + "*/html";

}
</script>

<h1>Staff Page Generator</h1><br />
<p>Please fill out the form and copy the code entered in the Green box.</p>
<form action="" name="info" onsubmit="return go()">
First Name - <br />

<input type="text" size="20" name="first"><br /><br />
Last Name - <br />
<input type="text" size="20" name="last"><br /><br />
Information - <br />
<input type="text" size="99" name="info"><br /><br />

<INPUT type="submit" value="Go"><br /><br /><br /><br /><br />
</form>






Author

RE: JS Page generator help


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 21-01-09 01:23
You have the error console for FF, don't you? Just load your script and that will tell you where your error is. Smile
Author

RE: JS Page generator help

spyware
Member



Posts: 4192
Location:
Joined: 14.04.07
Rank:
God
Warn Level: 90
Posted on 21-01-09 01:26
Escape. Look at the embedded HTML in your Javascript.



img507.imageshack.us/img507/3580/spynewsig3il1.png
"The chowner of property." - Zeph
[small]
Widespread intellectual and moral docility may be convenient for leaders in the short term,
but it is suicidal for nations in the long term.
- Carl Sagan
[center]�Since the grid is inescapable, what were the earlier lasers about? Does the corridor have a sense of humor?� - Ebert[/ce
Author

RE: JS Page generator help


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 21-01-09 02:11
spy is correct that you need to escape the / symbol in your tags. Also, I'm not sure that using "return function()" in the onsubmit event of your form will achieve the desired result (but, since I have never used it to do this, I could be wrong).

Explain more about how it isn't working... as in what it does or doesn't do. Saying "not sure what I did wrong" doesn't tell us anything.


Author

RE: JS Page generator help


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 21-01-09 02:36
Form

Code
<form action="form.html" name="info">
First Name - <br />
<input type="text" size="20" name="first"><br /><br />
Last Name - <br />
<input type="text" size="20" name="last"><br /><br />
Information - <br />
<input type="text" size="99" name="info"><br /><br />

<input type="submit" value="Go"><br /><br /><br /><br /><br />




Variable deceleration

Code
var first = document.info.first;
var last = document.info.last;
var info = document.info.info;

var name = first+" "+last;

var email = last+first.substring(0,1)+"@carthage.k12.mo.us";




and whenever I use document.write to print any of the variables it prints nothing, just makes the page go blank.



EDIT - Entire Code

index.html
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>Staff Page Generator</title>
</head>

<h1>Staff Page Generator</h1><br />
<p>Please fill out the form and copy the code entered in the Green box.</p>
<form action="form.html" name="form">
First Name - <br />
<input type="text" size="20" name="first"><br /><br />
Last Name - <br />
<input type="text" size="20" name="last"><br /><br />
Information - <br />
<input type="text" size="99" name="info"><br /><br />

<input type="submit" value="Go"><br /><br /><br /><br /><br />
</form>
<body>

</body>
</html>





Form.html
Code
<script>
var first = document.forms[0].first[0].value;
var last = document.forms[0].last[1].value;
var info = document.forms[0].info[2].value;

var name = first+" "+last;

var email = last+first.substring(0,1)+"@carthage.k12.mo.us";

</script>
<p style="background:#99FF99">

<script>
document.write("*!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"" + "*head" + "*title" + first "*/title*meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"*link href="style.css" rel="stylesheet" type="text/css" /*/head*body*table*tr class="blue"*td colspan="4"*h1"+name+"*/h1*/td*/tr*tr class="grey" *td width="160" rowspan="3" class="white" *img src="../Teacher Staff Photos/images/"+last+".gif" alt=""+name+"#" width="150" height="188"*td width="480" colspan="3" class="white""info"*/td*/tr*tr class="grey"*td colspan="3" class="white"*/td*/tr *tr class="grey""+" *td colspan="3" class="white"*a href="mailto:"+email+"#""+email+"*/a*/td*/table*p align="center"*img src="../images/BLUE-TIGER.gif" width="390" height="100"*/p*/body*/html");
</script>

</p>




EDIT 2 - stripped the ascii code out of it for some odd reason


Edit 3 - Live test
http://www.univer. . .index.html




Edited by on 21-01-09 03:37
Author

RE: JS Page generator help


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 21-01-09 11:21
Hi. I looked at your page with fire bug and it posts the following errors:

document.form is undefined

var first = document.form.first.value;

form.htm...nfo=infoa (line 11)

answer: var first = document.form.[first].value;


missing ) after argument list

document.write("*!DOCTYPE html PUBLI...#60;/body*/html");

form.htm...nfo=infoa (line 23)
answers: thers a typo somwre and the document.write('somthing') Not ""

Ps: it was just a quick look so I could be wromg... Sorry about the english...

Edited by on 21-01-09 11:22
Author

RE: JS Page generator help


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 21-01-09 12:30
Lemur wrote:
EDIT - Entire Code

Code

<form action="form.html" name="form">
First Name - <br />
<input type="text" size="20" name="first"><br /><br />
Last Name - <br />
<input type="text" size="20" name="last"><br /><br />
Information - <br />
<input type="text" size="99" name="info"><br /><br />

<input type="submit" value="Go"><br /><br /><br /><br /><br />
</form>





Where did the onsubmit go? Are you sure this is the entire code?

Lemur wrote:
Code
<script>
var first = document.forms[0].first[0].value;
var last = document.forms[0].last[1].value;
var info = document.forms[0].info[2].value;





I could've helped you to fix this earlier when we were discussing it over IM... but, at the time, it seemed as if you were more interested in "maintaining your pride" than fixing your problem. There's not a thing at all wrong with needing help... doesn't make us any less intelligent. People teach me crap all the time (well, not so much here... but, in real life).

That being said, you're combining two methods in that script block. Either you need to reference the items by name or by index... not both. If by name, take off the [0],[1]. and [2]. If by index, change the names to "elements" (no quotes). w3schools has a decent DOM reference... should be handy, so go check it out.


Author

RE: JS Page generator help

SySTeM
Member

Your avatar

Posts: 1524
Location: England, UK
Joined: 27.07.05
Rank:
HBH Guru
Posted on 21-01-09 15:29
document.write() is old school, try: document.createElementNS(), setAttribute(), document.createTextNode(), and appendChild()


img138.imageshack.us/img138/6527/sig2ak1.jpg
www.hellboundhackers.org/sig/r/2783.png

http://www.elites0ft.com/
Author

RE: JS Page generator help


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 22-01-09 23:53
http://www.carthage.k12.mo.us/jh/Staff%20Pages/generator.html

use the name Tom Moore.

I found out what I did wrong and apparently I used forward slashes instead of back slashes.


Author

RE: Just in case you are getting paid for this


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 23-01-09 02:10
Code

Such as Biography, courses taken, and a breif Personal piece. Note - to break up text put <br /> on the end of an area, two to make a new paragraph.





It is "brief", not "breif". And don't get me started on the "two to " make a new paragraph. Next, your handling of tags should be transparent to the user, not asking for BR tags in the context...

I am not trying to disrespect you, but this is unsat.

-Hawk
Author

RE: JS Page generator help


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 23-01-09 02:32
Lemur wrote:
New to Javascript programming

hawk_wolfram wrote:
And don't get me started on the "two to " make a new paragraph. Next, your handling of tags should be transparent to the user, not asking for BR tags in the context...

I am not trying to disrespect you, but this is unsat.

-Hawk

The most effective criticism is that which is followed by supporting arguments and, more importantly, more desirable alternatives. You say that the handling of tags should be transparent to the user (which is true), yet you provide not even basic supporting logic as an example.

How would you handle it? Be constructive, not just critical.


Author

RE: JS Page generator help


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 23-01-09 03:19
It was meant to work before I do anything such as that... Besides the fact I'm not sure if that's even possible to do in JS.


Author

RE: JS Page generator help


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 23-01-09 03:31
Lemur wrote:
Besides the fact I'm not sure if that's even possible to do in JS.

It is. Would work about the same as in your language of choice, except that JS has no "helper" functions for it (or, at least, I haven't seen them) like PHP's nl2br() (which is basically just a glorified str_replace). Also, newlines are interpreted differently by Windows, Linux, and Mac, so it would need to account for "\r\n", "\r", and "\n". Finally, you'll want to look into working with textarea selections to handle any font / text changes (bold, size, etc.).


Author

RE: JS Page generator help


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 23-01-09 12:53
Zephyr_Pure wrote:
Lemur wrote:
New to Javascript programming

hawk_wolfram wrote:
And don't get me started on the "two to " make a new paragraph. Next, your handling of tags should be transparent to the user, not asking for BR tags in the context...

I am not trying to disrespect you, but this is unsat.

-Hawk

The most effective criticism is that which is followed by supporting arguments and, more importantly, more desirable alternatives. You say that the handling of tags should be transparent to the user (which is true), yet you provide not even basic supporting logic as an example.

How would you handle it? Be constructive, not just critical.


Roger that Zeph. No excuse. I sounded like a judgemental asshat.

How would I handle it? I agree with Zeph, you simply need to have a function that leverages the correct regex (like taking the user's use of the "."Wink and goes through the input to replace all of the "."s with the newline delimiter that you want.

Under JS, the String object has the following methods for regexs:

replace(regexp, replaceStr) -- where the first arg is going to be the "." and the second arg is what you are replacing it with (i.e. "\r\n"Wink

split(regex) -- this one may be handy if you are parsing the input as lines separately as it returns an Array of the input broken up by the regex.

Lastly, like Zeph said, if the underlying OS is a factor for your newline char, then you could implement a switch statement for each OS, then call your replace function with the appropriate newline char as the supplied arg. Hope that helps, and please forgive me for showing my arse.

-Hawk
Author

RE: JS Page generator help


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 23-01-09 13:12
No worries, man. Looks like a good start on an approach. One of the best things about answering other people's programming questions would have to be working out the logic in something you've never thought through... or, even if you have, maybe finding a more efficient or different way to do it. Unfortunately, I doubt that the OP's JS creation will go any farther now that it works to some extent. :whoa: